@param \Error|\Exception|RestException $exception

@return RestResponse
@throws \Error|\Exception|RestException
198014
public static function exception(\Exception $exception)
    {
        if (!$exception instanceof RestException) {
            $exception = RestException::createFromException($exception);
        }

        return RestResponse::create(['errors' => $exception->errors()], $exception->getCode());
    }
875306
public function createResponse($exception)
    {
        if (!$exception instanceof FlattenException) {
            $exception = FlattenException::create($exception);
        }

        return new Response($this->decorate($this->getContent($exception, $this->showAllExceptions), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders());
    }
444661
private function httpExceptionResponse(ServerRequestInterface $request, HttpException $exception): ResponseInterface
    {
        if ($request->getHeaderLine('X-Requested-With') !== '') {
            $this->layout = 'layouts/ajax';
        }

        return $this->viewResponse('components/alert-danger', [
            'alert' => $exception->getMessage(),
            'title' => $exception->getMessage(),
        ], $exception->getStatusCode());
    }
1026017
protected function resolveResponseStatusCode(Exception $exception)
    {
        if ($exception instanceof HttpResponseException) {
            return $exception->getCode();
        } elseif ($exception instanceof HttpException) {
            return $exception->getStatusCode();
        } elseif ($exception instanceof OAuthException) {
            return $exception->httpStatusCode;
        } else {
            return 500;
        }
    }
712051
public function withException(\Exception $exception)
    {
        assert(!is_null($exception), 'Exception must not be null');

        return $this->withDetail('error', $exception->getMessage());
    }
156320
protected function checkResponse(array $response)
    {
        $responseCode = intval(array_get($response, '_curl_info.http_code'));
        $message = array_get($response, 'message');

        if ($responseCode >= 400) {
            $context = ['response_headers' => array_get($response, '_curl_info.response_headers')];
            throw new RestException($responseCode, $message, null, null, $context);
        }
    }
369368
private function handleError(ServerRequestInterface $request, HttpErrorException $exception): ResponseInterface
    {
        $request = $request->withAttribute($this->attribute, $exception);
        $handler = $this->handler ?: new ErrorHandlerDefault();

        return $handler->handle($request);
    }
1194113
protected function toDebugResponse( RequestInterface $request, PhpException $exception ) {
		if ( $request->isAjax() ) {
			return Response::json( [
				'message' => $exception->getMessage(),
				'exception' => get_class( $exception ),
				'file' => $exception->getFile(),
				'line' => $exception->getLine(),
				'trace' => array_map( function ( $trace ) {
					return Arr::except( $trace, ['args'] );
				}, $exception->getTrace() ),
			] )->withStatus( 500 );
		}

		if ( $this->whoops !== null ) {
			return $this->toPrettyErrorResponse( $exception );
		}

		throw $exception;
	}
856773
public function handleException(ServerRequestInterface $request, ResponseInterface $response, Exception $exception)
    {
        if ($level = $this->shouldLog('error')) {
            $this->logError($exception, $level);
        }

        return $this->handler->handleException($request, $response, $exception);
    }
290322
public function exceptionHandler($exception)
  {
    if (!\is_null($this->getResponse())) {
      # Run the Error Controller
      $response = $this->runErrorController('',500);

      # Set the error response
      $this->setResponse($response);
    } else {
      # Set HTTP Response Code - we dont even have a response object yet ..
      \http_response_code(500);

    }

    # Log the exception
    $this->getLogger()
         ->critical(
            $exception->getMessage().' in file '.$exception->getFile().' on line '.$exception->getLine(),
            $exception->getTrace()
          );

    return null;
  }
732832
public static function handleException($exception)
    {
        static::handleError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception, true);
    }
120213
private function error(HttpAdapterInterface $httpAdapter, HttpAdapterException $exception)
    {
        $request = $this->getTimer()->stop($exception->getRequest());

        $this->logger->error(
            sprintf(
                'Unable to send "%s %s".',
                $exception->getRequest()->getMethod(),
                (string) $exception->getRequest()->getUri()
            ),
            [
                'adapter'   => $httpAdapter->getName(),
                'exception' => $this->getFormatter()->formatException($exception),
                'request'   => $this->getFormatter()->formatRequest($request),
                'response'  => $exception->hasResponse()
                    ? $this->getFormatter()->formatResponse($exception->getResponse())
                    : null,
            ]
        );

        return $request;
    }
52461
protected function getErrorResponse(Exception $e)
    {
        switch (get_class($e)) {
            case ForbiddenException::class:
                $response = $this->forbidden(
                    new ErrorBag([new Error('Forbidden', $e->getMessage())])
                );
                break;
            default:
                $response = $this->errorResponse(
                    new ErrorBag([new Error('Bad Request', 'Request could not be served.')])
                );
        }

        return $response;
    }
641807
public function createExceptionResponse(\Exception $exception)
    {
        $responseData = [
            'code' => $exception->getCode(),
            'type' => static::TYPE_ERROR,
            'message' => $exception->getMessage(),
        ];

        if ($exception instanceof ValidationException) {
            $exception = new \KodiCMS\API\Exceptions\ValidationException($exception->validator);
        }

        if ($exception instanceof Exception or method_exists($exception, 'responseArray')) {
            $responseData = array_merge($responseData, $exception->responseArray());
        } else if ($exception instanceof ModelNotFoundException) {
            $responseData['code'] = static::ERROR_PAGE_NOT_FOUND;
        } else if ($exception instanceof MassAssignmentException) {
            $responseData['code']  = static::ERROR_MISSING_ASSIGMENT;
            $responseData['field'] = $exception->getMessage();
        }

        if ($this->debug) {
            $responseData['file'] = $exception->getFile();
            $responseData['line'] = $exception->getLine();
        }

        return $this->createResponse($responseData, 500);
    }
784246
public function handleException($exception)
	{
		$response = $this->callCustomHandlers($exception);

		// If one of the custom error handlers returned a response, we will send that
		// response back to the client after preparing it. This allows a specific
		// type of exceptions to handled by a Closure giving great flexibility.
		if ( ! is_null($response))
		{
			$response = $this->prepareResponse($response);
		}

		// If no response was sent by this custom exception handler, we will call the
		// default exception displayer for the current application context and let
		// it show the exception to the user / developer based on the situation.
		else
		{
			$response = $this->displayException($exception);
		}

		return $this->sendResponse($response);
	}
592114
protected function createException(GuzzleRequestException $exception): RequestException
    {
        if ($exception instanceof GuzzleResponseException) {
            return new ResponseException(
                $exception->getRequest(),
                $exception->getResponse(),
                $exception
            );
        }

        throw new RequestException(
            $exception->getRequest(),
            $exception
        );
    }
434039
protected function handleErrorResponses(HttpException $exception)
    {
        $status = $exception->getCode();
        $message = $exception->getStatusMessage();
        $solrRespone = new ResponseAdapter($exception->getBody());

        if ($status === 0 || $status === 502) {
            $e = new SolrUnavailableException('Solr Server not available: ' . $message, 1505989391);
            $e->setSolrResponse($solrRespone);
            throw $e;
        }

        if ($status === 500) {
            $e = new SolrInternalServerErrorException('Internal Server error during search: ' . $message, 1505989897);
            $e->setSolrResponse($solrRespone);
            throw $e;
        }

        $e = new SolrCommunicationException('Invalid query. Solr returned an error: ' . $status . ' ' . $message, 1293109870);
        $e->setSolrResponse($solrRespone);

        throw $e;
    }