Skip to content
Permalink
Browse files
Ensure To Display A Proper Error On Http Error
  • Loading branch information
Blair2004 committed Oct 1, 2021
1 parent 0138f96 commit b8fa0d9d8cd5d6596fbafc45233606dc77c496c1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
@@ -2,12 +2,14 @@

namespace App\Exceptions;

use App\Exceptions\MethodNotAllowedHttpException as ExceptionsMethodNotAllowedHttpException;
use App\Exceptions\QueryException as ExceptionsQueryException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException as MainValidationException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Throwable;

class Handler extends ExceptionHandler
@@ -89,6 +91,19 @@ public function render($request, Throwable $exception)
->render( $request );
}

if ( $exception instanceof MethodNotAllowedHttpException ) {
if ( $request->expectsJson() ) {
Log::error( $exception->getMessage() );

return response()->json([
'message' => env( 'APP_DEBUG' ) ? $exception->getMessage() : __( 'Invalid method used for the current request.' )
], 404);
}

return ( new ExceptionsMethodNotAllowedHttpException( $exception->getMessage() ) )
->render( $request );
}

return parent::render($request, $exception);
}
}
@@ -0,0 +1,15 @@
<?php

namespace App\Exceptions;

use Exception;

class MethodNotAllowedHttpException extends Exception
{
public function render( $message )
{
$message = $this->getMessage();
$title = __( 'Method Not Allowed' );
return response()->view( 'pages.errors.http-exception', compact( 'message', 'title' ), 500 );
}
}
@@ -0,0 +1,20 @@
@extends( 'layout.default' )

@section( 'layout.default.body' )
<div class="h-full w-full overflow-y-auto pb-10 bg-gradient-to-bl from-teal-500 to-blue-500 flex items-center justify-center">
<div class="w-full md:w-1/2 xl:1/3 flex items-center flex-col justify-center">
<span class="rounded-full text-6xl w-24 h-24 flex items-center justify-center bg-white shadow text-red-500 mb-4">
<i class="las la-hand-paper"></i>
</span>
<h1 class="text-white text-3xl mb-2 lg:text-5xl font-bold text-center">{!! $title ?? __( 'Method Not Allowed' ) !!}</h1>
<div class="my-2 shadow overflow-hidden rounded bg-white w-95vw md:w-3/4 lg:w-3/5">
<p class="md:w-auto w-95vw bg-gray-700 text-gray-100 lg:text-lg text-center p-4">{{ $message }}</p>
</div>
<div class="flex md:flex-row flex-col -mx-4 my-4 flex-wrap w-56 lg:w-auto">
<div class="px-4 mb-4"><a class="block w-full lg:w-auto btn bg-white text-gray-700" href="{{ ! empty( request()->query( 'back' ) ) ? urldecode( request()->query( 'back' ) ) : url()->previous() }}"><i class="las la-angle-left"></i> {{ __( 'Go Back' ) }}</a></div>
<div class="px-4 mb-4"><a class="block w-full lg:w-auto btn bg-white text-gray-700" href="{{ url()->current() . '?back=' . urlencode( request()->query( 'back' ) ?? url()->previous() ) }}"><i class="las la-sync"></i> {{ __( 'Try Again' ) }}</a></div>
<div class="px-4 mb-4"><a class="block w-full lg:w-auto btn bg-white text-gray-700" href="https://my.nexopos.com/en/documentation"><i class="las la-cog"></i> {{ __( 'Documentation' ) }}</a></div>
</div>
</div>
</div>
@endsection

0 comments on commit b8fa0d9

Please sign in to comment.