-
-
Save Oranzh/e872be15afb32fd82979f4ab21cc2a3a to your computer and use it in GitHub Desktop.
Revisions
-
joseluisq revised this gist
Aug 28, 2018 . No changes.There are no files selected for viewing
-
joseluisq revised this gist
Aug 28, 2018 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,13 +53,10 @@ public function render($request, Exception $e) return parent::render($request, $e); } $status = Response::HTTP_INTERNAL_SERVER_ERROR; if ($e instanceof HttpResponseException) { $status = Response::HTTP_INTERNAL_SERVER_ERROR; } elseif ($e instanceof MethodNotAllowedHttpException) { $status = Response::HTTP_METHOD_NOT_ALLOWED; $e = new MethodNotAllowedHttpException([], 'HTTP_METHOD_NOT_ALLOWED', $e); @@ -72,13 +69,12 @@ public function render($request, Exception $e) } elseif ($e instanceof \Dotenv\Exception\ValidationException && $e->getResponse()) { $status = Response::HTTP_BAD_REQUEST; $e = new \Dotenv\Exception\ValidationException('HTTP_BAD_REQUEST', $status, $e); } elseif ($e) { $e = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR'); } return response()->json([ 'success' => false, 'status' => $status, 'message' => $e->getMessage() ], $status); -
joseluisq revised this gist
Apr 18, 2017 . 2 changed files with 2 additions and 9 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,34 +53,27 @@ public function render($request, Exception $e) return parent::render($request, $e); } $success = false; $response = null; $status = Response::HTTP_INTERNAL_SERVER_ERROR; if ($e instanceof HttpResponseException) { $status = Response::HTTP_INTERNAL_SERVER_ERROR; $response = $e->getResponse(); } elseif ($e instanceof MethodNotAllowedHttpException) { $status = Response::HTTP_METHOD_NOT_ALLOWED; $e = new MethodNotAllowedHttpException([], 'HTTP_METHOD_NOT_ALLOWED', $e); } elseif ($e instanceof NotFoundHttpException) { $status = Response::HTTP_NOT_FOUND; $e = new NotFoundHttpException('HTTP_NOT_FOUND', $e); } elseif ($e instanceof AuthorizationException) { $status = Response::HTTP_FORBIDDEN; $e = new AuthorizationException('HTTP_FORBIDDEN', $status); } elseif ($e instanceof \Dotenv\Exception\ValidationException && $e->getResponse()) { $status = Response::HTTP_BAD_REQUEST; $e = new \Dotenv\Exception\ValidationException('HTTP_BAD_REQUEST', $status, $e); $response = $e->getResponse(); } elseif ($e) { $e = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR'); } -
joseluisq revised this gist
Apr 18, 2017 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,8 +53,8 @@ public function render($request, Exception $e) return parent::render($request, $e); } $success = true; $status = Response::HTTP_OK; $response = null; if ($e instanceof HttpResponseException) { -
joseluisq revised this gist
Apr 18, 2017 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,32 +54,32 @@ public function render($request, Exception $e) } $status = 200; $success = true; $response = null; if ($e instanceof HttpResponseException) { $success = false; $status = Response::HTTP_INTERNAL_SERVER_ERROR; $response = $e->getResponse(); } elseif ($e instanceof MethodNotAllowedHttpException) { $success = false; $status = Response::HTTP_METHOD_NOT_ALLOWED; $e = new MethodNotAllowedHttpException([], 'HTTP_METHOD_NOT_ALLOWED', $e); } elseif ($e instanceof NotFoundHttpException) { $success = false; $status = Response::HTTP_NOT_FOUND; $e = new NotFoundHttpException('HTTP_NOT_FOUND', $e); } elseif ($e instanceof AuthorizationException) { $success = false; $status = Response::HTTP_FORBIDDEN; $e = new AuthorizationException('HTTP_FORBIDDEN', $status); } elseif ($e instanceof \Dotenv\Exception\ValidationException && $e->getResponse()) { $success = false; $status = Response::HTTP_BAD_REQUEST; $e = new \Dotenv\Exception\ValidationException('HTTP_BAD_REQUEST', $status, $e); $response = $e->getResponse(); } elseif ($e) { $success = false; $status = Response::HTTP_INTERNAL_SERVER_ERROR; $e = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR'); } -
joseluisq revised this gist
Apr 13, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Lumen 5 HTTP Exception Handlers with JSON support. > Configure [PHP Lumen 5](https://lumen.laravel.com/) HTTP Exception Handlers with common JSON responses.  -
joseluisq revised this gist
Apr 13, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Lumen 5 HTTP Exceptions Handler with JSON support. > Configure [PHP Lumen 5](https://lumen.laravel.com/) HTTP Exceptions Handler with common JSON responses.  -
joseluisq revised this gist
Apr 13, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,3 +7,5 @@ ### Setup Copy (replace) only the attached files to their respective directories. `app/Exceptions/Handler.php` and `app/Http/Middleware/Authenticate.php` __Tip:__ Via your `.env` file you can handle the visibility of the HTTP Exception responses. `APP_DEBUG=false` (for display json exception responses in production) -
joseluisq revised this gist
Apr 13, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,4 +6,4 @@ ### Setup Copy (replace) only the attached files to their respective directories. `app/Exceptions/Handler.php` and `app/Http/Middleware/Authenticate.php` -
joseluisq renamed this gist
Apr 13, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
joseluisq created this gist
Apr 13, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ <?php namespace App\Http\Middleware; use Closure; use Illuminate\Contracts\Auth\Factory as Auth; class Authenticate { /** * The authentication guard factory instance. * * @var \Illuminate\Contracts\Auth\Factory */ protected $auth; /** * Create a new middleware instance. * * @param \Illuminate\Contracts\Auth\Factory $auth * @return void */ public function __construct(Auth $auth) { $this->auth = $auth; } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) { if ($this->auth->guard($guard)->guest()) { return response() ->json([ 'success' => false, 'status' => 401, 'message' => 'HTTP_UNAUTHORIZED' ], 401); } return $next($request); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # Lumen 5 Exceptions Handler with JSON support. > Configure [PHP Lumen 5](https://lumen.laravel.com/) Exceptions Handler with JSON responses.  ### Setup Copy (replace) only the attached files to their respective directories. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,93 @@ <?php namespace App\Exceptions; use Exception; use Illuminate\Validation\ValidationException; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\ModelNotFoundException; use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Illuminate\Http\Exception\HttpResponseException; use Illuminate\Http\Response; class Handler extends ExceptionHandler { /** * A list of the exception types that should not be reported. * * @var array */ protected $dontReport = [ AuthorizationException::class, HttpException::class, ModelNotFoundException::class, ValidationException::class, ]; /** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * * @param \Exception $e * @return void */ public function report(Exception $e) { parent::report($e); } /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if (env('APP_DEBUG')) { return parent::render($request, $e); } $status = 200; $success = TRUE; $response = NULL; if ($e instanceof HttpResponseException) { $success = FALSE; $status = Response::HTTP_INTERNAL_SERVER_ERROR; $response = $e->getResponse(); } elseif ($e instanceof MethodNotAllowedHttpException) { $success = FALSE; $status = Response::HTTP_METHOD_NOT_ALLOWED; $e = new MethodNotAllowedHttpException([], 'HTTP_METHOD_NOT_ALLOWED', $e); } elseif ($e instanceof NotFoundHttpException) { $success = FALSE; $status = Response::HTTP_NOT_FOUND; $e = new NotFoundHttpException('HTTP_NOT_FOUND', $e); } elseif ($e instanceof AuthorizationException) { $success = FALSE; $status = Response::HTTP_FORBIDDEN; $e = new AuthorizationException('HTTP_FORBIDDEN', $status); } elseif ($e instanceof \Dotenv\Exception\ValidationException && $e->getResponse()) { $success = FALSE; $status = Response::HTTP_BAD_REQUEST; $e = new \Dotenv\Exception\ValidationException('HTTP_BAD_REQUEST', $status, $e); $response = $e->getResponse(); } elseif ($e) { $success = FALSE; $status = Response::HTTP_INTERNAL_SERVER_ERROR; $e = new HttpException($status, 'HTTP_INTERNAL_SERVER_ERROR'); } return response()->json([ 'success' => $success, 'status' => $status, 'message' => $e->getMessage() ], $status); } }