Dingo\Api\Exception\Handler::handle PHP Method

handle() public method

Handle an exception if it has an existing handler.
public handle ( Exception $exception ) : Illuminate\Http\Response
$exception Exception
return Illuminate\Http\Response
    public function handle(Exception $exception)
    {
        foreach ($this->handlers as $hint => $handler) {
            if (!$exception instanceof $hint) {
                continue;
            }
            if ($response = $handler($exception)) {
                if (!$response instanceof BaseResponse) {
                    $response = new Response($response, $this->getExceptionStatusCode($exception));
                }
                return $response;
            }
        }
        return $this->genericResponse($exception);
    }

Usage Example

Example #1
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         if ($this->validator->validateRequest($request)) {
             $request = $this->app->make('Dingo\\Api\\Contract\\Http\\Request')->createFromIlluminate($request);
             return $this->sendRequestThroughRouter($request);
         }
     } catch (Exception $exception) {
         return $this->exception->handle($exception);
     }
     return $next($request);
 }
All Usage Examples Of Dingo\Api\Exception\Handler::handle