Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
fecd130a
Commit
fecd130a
authored
Mar 11, 2018
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
error handeling for API
parent
37045a8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
Handler.php
app/Exceptions/Handler.php
+58
-0
No files found.
app/Exceptions/Handler.php
View file @
fecd130a
...
...
@@ -6,6 +6,12 @@ use Exception;
use
Illuminate\Auth\AuthenticationException
;
use
Illuminate\Foundation\Exceptions\Handler
as
ExceptionHandler
;
use
Illuminate\Session\TokenMismatchException
;
use
Illuminate\Database\Eloquent\ModelNotFoundException
;
use
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
;
use
Symfony\Component\HttpKernel\Exception\BadRequestHttpException
;
use
Illuminate\Validation\ValidationException
;
class
Handler
extends
ExceptionHandler
{
...
...
@@ -62,6 +68,58 @@ class Handler extends ExceptionHandler
return
redirect
()
->
back
()
->
withInput
()
->
withFlashDanger
(
$exception
->
getMessage
());
}
if
(
strpos
(
$request
->
url
(),
'/api/'
)
!==
false
)
{
\Log
::
debug
(
"API Request Exception - "
.
$request
->
url
()
.
" - "
.
$exception
->
getMessage
()
.
(
!
empty
(
$request
->
all
())
?
' - '
.
json_encode
(
$request
->
except
([
'password'
]))
:
''
));
if
(
$exception
instanceof
MethodNotAllowedHttpException
)
{
return
response
()
->
json
((
object
)
[
'status'
=>
false
,
'errorCode'
=>
'METHOD_NOT_ALLOWED'
,
'message'
=>
'Please check HTTP Request Method. - MethodNotAllowedHttpException'
],
403
);
}
if
(
$exception
instanceof
NotFoundHttpException
)
{
return
response
()
->
json
((
object
)
[
'status'
=>
false
,
'errorCode'
=>
'URL_NOT_FOUND'
,
'message'
=>
'Please check your URL to make sure request is formatted properly. - NotFoundHttpException'
],
403
);
}
if
(
$exception
instanceof
GeneralException
)
{
return
response
()
->
json
((
object
)
[
'status'
=>
false
,
'errorCode'
=>
'EXCEPTION'
,
'message'
=>
$exception
->
getMessage
()
],
403
);
}
if
(
$exception
instanceof
ModelNotFoundException
)
{
return
response
()
->
json
((
object
)
[
'status'
=>
false
,
'errorCode'
=>
'ITEM_NOT_FOUND'
,
'message'
=>
'Item could not be found. Please check identifier.'
],
403
);
}
if
(
$exception
instanceof
ValidationException
)
{
\Log
::
debug
(
"API Validation Exception - "
.
json_encode
(
$exception
->
validator
->
messages
()));
return
response
()
->
json
((
object
)
[
'status'
=>
false
,
'errorCode'
=>
'VALIDATION_EXCEPTION'
,
'messages'
=>
$exception
->
validator
->
messages
()
],
403
);
}
}
return
parent
::
render
(
$request
,
$exception
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment