Skip to content

Commit 650ad01

Browse files
Fix
1 parent 87fbbbe commit 650ad01

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Utils/HasBookAttribute.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Code16\LaravelTiteliveClient\Utils;
44

55
use Code16\LaravelTiteliveClient\Api\Clients\BookCache;
6+
use Code16\LaravelTiteliveClient\Api\Clients\TiteLive\TiteLiveBookNotFoundException;
67
use Code16\LaravelTiteliveClient\Book;
78
use Illuminate\Database\Eloquent\Casts\Attribute;
89

@@ -13,11 +14,15 @@ trait HasBookAttribute
1314
{
1415
public function refreshBook(bool $force = false): self
1516
{
16-
$this->update([
17-
'book' => app(BookCache::class)
18-
->force($force)
19-
->refreshIfNeeded($this->book),
20-
]);
17+
try {
18+
$this->update([
19+
'book' => $refreshedBook = app(BookCache::class)
20+
->force($force)
21+
->refreshIfNeeded($this->book),
22+
]);
23+
} catch(TiteLiveBookNotFoundException $e) {
24+
$this->delete();
25+
}
2126

2227
return $this;
2328
}

0 commit comments

Comments
 (0)