Skip to content

anilkumarthakur60/Exception-Response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exception Handler for api

About

The purpose of this method is to handle exceptions that occur during the execution of the application.

The method first checks if the request path matches the pattern 'api/*' or if the request expects a JSON response. If either of these conditions is true, it calls the apiException method and passes in the $request and $exception parameters. This method likely handles the exception and returns a JSON response.

If the request does not match the pattern 'api/*' and does not expect a JSON response, the method calls the parent render method and passes in the $request and $exception parameters. This will likely render a standard error page.

Overall, this code appears to be part of an error handling system that differentiates between API requests and other requests and provides appropriate error responses for each.

Installation

Composer

composer require anil/exception-response

Use inside Handler.php


use Anil\ExceptionResponse\Traits\ApiExceptionResponse;
class Handler extends ExceptionHandler
{
    use ApiExceptionResponse;
    
    public function render($request, Throwable $exception)
    {
        if ($request->is('api/*') || $request->expectsJson()) {

            return $this->apiException($request, $exception);
        }

        return parent::render($request, $exception);
    }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages