Skip to content

Commit 1cdbb73

Browse files
author
Shashank Jain
committed
Feat: add handler for ModelNotFoundException
1 parent 06dd9e9 commit 1cdbb73

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Handlers/ApiExceptionHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Froiden\RestAPI\Exceptions\Parse\UnknownFieldException;
99
use Froiden\RestAPI\Exceptions\UnauthorizedException;
1010
use Froiden\RestAPI\Exceptions\ValidationException;
11+
use Illuminate\Database\Eloquent\ModelNotFoundException;
1112
use Illuminate\Database\QueryException;
1213
use Illuminate\Http\Exception\HttpResponseException;
1314
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -33,6 +34,11 @@ public function render($request, \Exception $e)
3334
'url' => request()->url()
3435
]));
3536
}
37+
else if ($e instanceof ModelNotFoundException) {
38+
return ApiResponse::exception(new ApiException('Requested resource not found', null, 404, 404, null, [
39+
'url' => request()->url()
40+
]));
41+
}
3642
else if ($e instanceof ApiException) {
3743
return ApiResponse::exception($e);
3844
}

0 commit comments

Comments
 (0)