@@ -229,44 +229,20 @@ public function request($type, $file = null)
229
229
// get the response and the HTTP status code
230
230
list ($ response , $ status ) = $ this ->exec ($ options );
231
231
232
- switch ($ status )
232
+ // request completed successfully
233
+ if ($ status == 200 && $ type == 'meta ' )
233
234
{
234
- // request completed successfully
235
- case 200 :
236
- if ($ type == 'meta ' )
237
- {
238
- $ response = Metadata::make ($ response , $ file );
239
- }
240
- break ;
241
-
242
- // request completed sucessfully but result is empty
243
- case 204 :
244
- $ response = null ;
245
- break ;
246
-
247
- // method not allowed
248
- case 405 :
249
- throw new Exception ('Method not allowed ' );
250
- break ;
251
-
252
- // unsupported media type
253
- case 415 :
254
- throw new Exception ('Unsupported media type ' );
255
- break ;
256
-
257
- // unprocessable entity
258
- case 422 :
259
- throw new Exception ('Unprocessable document ' );
260
- break ;
261
-
262
- // server error
263
- case 500 :
264
- throw new Exception ('Error while processing document ' );
265
- break ;
266
-
267
- // unexpected
268
- default :
269
- throw new Exception ("Unexpected response for / $ resource ( $ status) " );
235
+ $ response = Metadata::make ($ response , $ file );
236
+ }
237
+ // request completed successfully but result is empty
238
+ elseif ($ status == 200 || $ status == 204 )
239
+ {
240
+ $ response = null ;
241
+ }
242
+ // other status code is an error
243
+ else
244
+ {
245
+ $ this ->error ($ status , $ resource );
270
246
}
271
247
272
248
// cache certain responses
@@ -308,4 +284,44 @@ protected function exec(array $options = [])
308
284
309
285
return $ response ;
310
286
}
287
+
288
+ /**
289
+ * Throws an exception for an error status code
290
+ *
291
+ * @codeCoverageIgnore
292
+ *
293
+ * @param int $status
294
+ * @param string $resource
295
+ *
296
+ * @throws Exception
297
+ */
298
+ protected function error ($ status , $ resource )
299
+ {
300
+ switch ($ status )
301
+ {
302
+ // method not allowed
303
+ case 405 :
304
+ throw new Exception ('Method not allowed ' );
305
+ break ;
306
+
307
+ // unsupported media type
308
+ case 415 :
309
+ throw new Exception ('Unsupported media type ' );
310
+ break ;
311
+
312
+ // unprocessable entity
313
+ case 422 :
314
+ throw new Exception ('Unprocessable document ' );
315
+ break ;
316
+
317
+ // server error
318
+ case 500 :
319
+ throw new Exception ('Error while processing document ' );
320
+ break ;
321
+
322
+ // unexpected
323
+ default :
324
+ throw new Exception ("Unexpected response for / $ resource ( $ status) " );
325
+ }
326
+ }
311
327
}
0 commit comments