Skip to content

Commit

Permalink
Merge bd8ed74 into 93db86b
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszUrbanowicz committed Nov 21, 2015
2 parents 93db86b + bd8ed74 commit 870d539
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions app/Exceptions/Handler.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;
use Gzero\Validator\ValidationException;
use Gzero\Api\AccessForbiddenException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler {

const VALIDATION_ERROR = 400; // (Bad Request)
const SERVER_ERROR = 500; // (Internal Server Error)
const FORBIDDEN_ERROR = 403; // (Forbidden Error)

/**
* A list of the exception types that should not be reported.
Expand Down Expand Up @@ -59,35 +61,48 @@ public function render($request, Exception $e)
),
$request
);
} else if (App::environment() == 'production') {
} elseif ($e instanceof AccessForbiddenException) {
return $CORS->addActualRequestHeaders(
response()->json(
[
'code' => self::SERVER_ERROR,
'error' => [
'message' => ($e->getMessage()) ? $e->getMessage() : 'Internal Server Error',
]
'code' => self::FORBIDDEN_ERROR,
'error' => ($e->getMessage()) ? $e->getMessage() : 'Forbidden.'
],
self::SERVER_ERROR
self::FORBIDDEN_ERROR
),
$request
);
} else {
return $CORS->addActualRequestHeaders(
response()->json(
[
'code' => self::SERVER_ERROR,
'error' => [
'type' => get_class($e),
'message' => ($e->getMessage()) ? $e->getMessage() : 'Internal Server Error',
'file' => $e->getFile(),
'line' => $e->getLine(),
]
],
self::SERVER_ERROR
),
$request
);
if (App::environment() == 'production') {
return $CORS->addActualRequestHeaders(
response()->json(
[
'code' => self::SERVER_ERROR,
'error' => [
'message' => ($e->getMessage()) ? $e->getMessage() : 'Internal Server Error',
]
],
self::SERVER_ERROR
),
$request
);
} else {
return $CORS->addActualRequestHeaders(
response()->json(
[
'code' => self::SERVER_ERROR,
'error' => [
'type' => get_class($e),
'message' => ($e->getMessage()) ? $e->getMessage() : 'Internal Server Error',
'file' => $e->getFile(),
'line' => $e->getLine(),
]
],
self::SERVER_ERROR
),
$request
);
}
}
} else {
if (config('app.debug')) {
Expand Down

0 comments on commit 870d539

Please sign in to comment.