also looking at this
Exceptions
#27
5 files
+168
-14
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -7,15 +7,13 @@ use Exception; | ||
| 7 | 7 | class InvalidFormatException extends Exception |
| 8 | 8 | { |
| 9 | 9 | /** |
| 10 | * Render the exception as an HTTP response. | |
| 10 | * Construct exception. | |
| 11 | 11 | * |
| 12 | * @return string | |
| 12 | * @param string $message | |
| 13 | 13 | */ |
| 14 | public function errorMessage(): string | |
| 14 | public function __construct(string $message = null) | |
| 15 | 15 | { |
| 16 | $errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile() | |
| 17 | .' ID is not a valid integer'; | |
| 18 | ||
| 19 | return $errorMsg; | |
| 16 | parent::__construct($message ?? 'Error on line '.$this->getLine().' in '.$this->getFile() | |
| 17 | .' ID is not a valid integer'); | |
| 20 | 18 | } |
| 21 | 19 | } |
| @@ -65,7 +65,7 @@ class Folder | ||
| 65 | 65 | |
| 66 | 66 | $ids = is_array($id) ? $id : func_get_args(); |
| 67 | 67 | } catch (InvalidFormatException $e) { |
| 68 | return $e->errorMessage(); | |
| 68 | return $e->getMessage(); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return $this->client->request('GET', 'folders', ['folder_ids' => $ids]); |
| @@ -89,7 +89,7 @@ class Folder | ||
| 89 | 89 | |
| 90 | 90 | $response = $this->client->request('GET', "folders/${id}"); |
| 91 | 91 | } catch (InvalidFormatException $e) { |
| 92 | return $e->errorMessage(); | |
| 92 | return $e->getMessage(); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | return new Response($this, $response); |
| @@ -132,7 +132,7 @@ class Folder | ||
| 132 | 132 | |
| 133 | 133 | $name = is_array($name) ? $name : compact('name'); |
| 134 | 134 | } catch (InvalidFormatException $e) { |
| 135 | return $e->errorMessage(); | |
| 135 | return $e->getMessage(); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | return $this->client->request('PATCH', "folders/{$id}", $name); |
| @@ -158,7 +158,7 @@ class Folder | ||
| 158 | 158 | return $this->deleteFolderFromMedia($this->model->getId(), $id); |
| 159 | 159 | } |
| 160 | 160 | } catch (InvalidFormatException $e) { |
| 161 | return $e->errorMessage(); | |
| 161 | return $e->getMessage(); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | return $this->client->request('DELETE', "folders/{$id}"); |
| @@ -194,7 +194,7 @@ class Folder | ||
| 194 | 194 | |
| 195 | 195 | return $this->client->request('POST', "folders/{$id}/archive"); |
| 196 | 196 | } catch (InvalidFormatException $e) { |
| 197 | return $e->errorMessage(); | |
| 197 | return $e->getMessage(); | |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| @@ -216,7 +216,7 @@ class Folder | ||
| 216 | 216 | |
| 217 | 217 | return $this->client->request('POST', "folders/{$id}/unarchive"); |
| 218 | 218 | } catch (InvalidFormatException $e) { |
| 219 | return $e->errorMessage(); | |
| 219 | return $e->getMessage(); | |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| @@ -238,7 +238,7 @@ class Folder | ||
| 238 | 238 | |
| 239 | 239 | return $this->client->request('POST', "folders/{$id}/duplicate"); |
| 240 | 240 | } catch (InvalidFormatException $e) { |
| 241 | return $e->errorMessage(); | |
| 241 | return $e->getMessage(); | |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| @@ -260,7 +260,7 @@ class Folder | ||
| 260 | 260 | |
| 261 | 261 | return $this->client->request('POST', "media/{$id}/folders", $name); |
| 262 | 262 | } catch (InvalidFormatException $e) { |
| 263 | return $e->errorMessage(); | |
| 263 | return $e->getMessage(); | |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| @@ -283,7 +283,7 @@ class Folder | ||
| 283 | 283 | |
| 284 | 284 | return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}"); |
| 285 | 285 | } catch (InvalidFormatException $e) { |
| 286 | return $e->errorMessage(); | |
| 286 | return $e->getMessage(); | |
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
| @@ -67,7 +67,7 @@ class Media | ||
| 67 | 67 | |
| 68 | 68 | $ids = is_array($id) ? $id : func_get_args(); |
| 69 | 69 | } catch (InvalidFormatException $e) { |
| 70 | return $e->errorMessage(); | |
| 70 | return $e->getMessage(); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | return $this->client->request('GET', 'media/show', ['media_ids' => $ids]); |
| @@ -91,7 +91,7 @@ class Media | ||
| 91 | 91 | |
| 92 | 92 | $response = $this->client->request('GET', "media/${id}"); |
| 93 | 93 | } catch (InvalidFormatException $e) { |
| 94 | return $e->errorMessage(); | |
| 94 | return $e->getMessage(); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return new Response($this, $response); |
| @@ -132,7 +132,7 @@ class Media | ||
| 132 | 132 | |
| 133 | 133 | return $this->client->request('PATCH', "media/{$id}/file-name", $name); |
| 134 | 134 | } catch (InvalidFormatException $e) { |
| 135 | return $e->errorMessage(); | |
| 135 | return $e->getMessage(); | |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| @@ -154,7 +154,7 @@ class Media | ||
| 154 | 154 | |
| 155 | 155 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); |
| 156 | 156 | } catch (InvalidFormatException $e) { |
| 157 | return $e->errorMessage(); | |
| 157 | return $e->getMessage(); | |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
| @@ -188,7 +188,7 @@ class Media | ||
| 188 | 188 | |
| 189 | 189 | return $this->client->request('POST', "media/{$id}/archive"); |
| 190 | 190 | } catch (InvalidFormatException $e) { |
| 191 | return $e->errorMessage(); | |
| 191 | return $e->getMessage(); | |
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
| @@ -210,7 +210,7 @@ class Media | ||
| 210 | 210 | |
| 211 | 211 | return $this->client->request('POST', "media/{$id}/unarchive"); |
| 212 | 212 | } catch (InvalidFormatException $e) { |
| 213 | return $e->errorMessage(); | |
| 213 | return $e->getMessage(); | |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
| @@ -232,7 +232,7 @@ class Media | ||
| 232 | 232 | |
| 233 | 233 | return $this->client->request('PATCH', "media/{$id}/make-private"); |
| 234 | 234 | } catch (InvalidFormatException $e) { |
| 235 | return $e->errorMessage(); | |
| 235 | return $e->getMessage(); | |
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | |
| @@ -254,7 +254,7 @@ class Media | ||
| 254 | 254 | |
| 255 | 255 | return $this->client->request('PATCH', "media/{$id}/make-public"); |
| 256 | 256 | } catch (InvalidFormatException $e) { |
| 257 | return $e->errorMessage(); | |
| 257 | return $e->getMessage(); | |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| @@ -276,7 +276,7 @@ class Media | ||
| 276 | 276 | |
| 277 | 277 | return $this->client->request('POST', "media/{$id}/duplicate"); |
| 278 | 278 | } catch (InvalidFormatException $e) { |
| 279 | return $e->errorMessage(); | |
| 279 | return $e->getMessage(); | |
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |