Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403_ajax_handler #18

Merged
merged 3 commits into from
Nov 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about 403 production case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is working for both production and develop cases

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