Creates MountebankException instance from mountebank response

@param ClientException $e
@return MountebankException
484253
private function convertToMountebankException(ClientException $e)
    {
        return $this->exceptionFactory->createInstanceFromMountebankResponse(
            (string)$e->getResponse()->getBody()
        );
    }
1089342
public static function fromMultiTransferException(MultiTransferException $e)
    {
        $ce = new self($e->getMessage(), $e->getCode(), $e->getPrevious());
        $ce->setSuccessfulRequests($e->getSuccessfulRequests());

        $alreadyAddedExceptions = array();
        foreach ($e->getFailedRequests() as $request) {
            if ($re = $e->getExceptionForFailedRequest($request)) {
                $alreadyAddedExceptions[] = $re;
                $ce->addFailedRequestWithException($request, $re);
            } else {
                $ce->addFailedRequest($request);
            }
        }

        // Add any exceptions that did not map to a request
        if (count($alreadyAddedExceptions) < count($e)) {
            foreach ($e as $ex) {
                if (!in_array($ex, $alreadyAddedExceptions)) {
                    $ce->add($ex);
                }
            }
        }

        return $ce;
    }
310287
private function mapException(ControllerException $exception): ClientException
    {
        switch ($exception->getCode()) {
            case ControllerException::BAD_ACTION:
                //no break
            case ControllerException::NOT_FOUND:
                return new NotFoundException($exception->getMessage());
            case ControllerException::FORBIDDEN:
                return new ForbiddenException($exception->getMessage());
            default:
                return new BadRequestException($exception->getMessage());
        }
    }
1215844
public static function buildExceptionStore(\Exception $e)
    {
        $exceptionStore = new ExceptionStore();
        $exceptionStore->setMessage($e->getMessage());
        $exceptionStore->setCode($e->getCode());
        $exceptionStore->setExceptionClass(get_class($e));
        $t = explode('\n', $e->getTraceAsString());
        $exceptionStore->setStack($t);

        $stack = $e->getTrace();
        if (count($stack) > 0) {
            //Setting default unknown values
            $exceptionStore->setFile("unknown");
            $exceptionStore->setLine(0);
            //Searching for a valid stackItem
            $stackItem = static::searchForFileAndLineCalledFromStack($stack);
            if (!is_null($stackItem)) {
                $exceptionStore->setFile(basename($stackItem['file'],'.php'));
                $exceptionStore->setLine($stackItem['line']);
            }
        }

        return $exceptionStore;
    }
774640
protected function convertMySqlException(\PDOException $e, \Exception $root)
	{
		$code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : $e->getCode();
	
		switch($code)
		{
			case '1216':
			case '1217':
			case '1451':
			case '1452':
			case '1701':
				return new ForeignKeyConstraintViolationException($root->getMessage(), 0, $root);
			case '1062':
			case '1557':
			case '1569':
			case '1586':
				return new UniqueConstraintViolationException($root->getMessage(), 0, $root);
		}
	
		return new DatabaseException($root->getMessage(), 0, $root);
	}
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;
    }
63891
protected function transformMediaUploadException(Exception $e)
    {
        if ($e instanceof MediaUploadException) {
            $status_code = $this->getStatusCodeForMediaUploadException($e);
            return new HttpException($status_code, $e->getMessage(), $e);
        }

        return $e;
    }
572493
protected function doException(\Exception $e)
    {
        $output = (new ResponseInjector)->build();

        $errorController = (new Injector)->param('errorController');
        $errorAction = (new Injector)->param('errorAction');

        if (!$errorController || !$errorAction) { // render SAPI error not configured
            $stream = $output->getBody();
            $stream->write('Option `errorController` or `errorAction` not configured');

            return $output->withBody($stream);
        }

        // Render SAPI error
        $body = (new RequestInjector)->build()->getParsedBody();
        $body['error'] = $e;

        $request = (new RequestInjector)->build()->withParsedBody($body);
        (new Injector)->addRequirement('request', $request);

        $controller = $errorController;

        /** @var \Micro\Mvc\Controllers\IController $result */
        $result = new $controller(false);
        $result = $result->action($errorAction);

        if ($result instanceof ResponseInterface) {
            return $result;
        }

        $stream = $output->getBody();
        $stream->write((string)$result);

        return $output->withBody($stream);
    }
66286
protected function determineException(ClientException $exception): Exception
    {
        if (in_array($exception->getResponse()->getStatusCode(), [400, 403, 404, 409])) {
            return new BadRequest($exception->getResponse());
        }

        return $exception;
    }
454183
public function appException($e)
    {
        throw new ErrorException($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTrace());

    }
921208
private function getJsonException(\Exception $e)
    {
        $file = Path::makeRelative($e->getFile(), $this->app['path_resolver']->resolve('root'));

        $error = [
            'error' => [
                'type'    => get_class($e),
                'file'    => $file,
                'line'    => $e->getLine(),
                'message' => $e->getMessage(),
            ],
        ];

        return new JsonResponse($error, Response::HTTP_INTERNAL_SERVER_ERROR);
    }
1118336
public static function createFromException($e, $level, array $context = [])
    {
        return new static($e->getMessage(), $level, $context, $e->getCode(), $e->getPrevious());
    }
202315
private function handleExternalError(\Exception $e) {
        $reflection = new \ReflectionClass($e);
        echo '<header>';
            echo '<h1>Exception: ' . $reflection->getName() . '</h1>';
            echo '<h2>Message: ' . $e->getMessage() . '</h2>';
            echo '<h3>' . $e->getFile() . ':' . $e->getLine() . '</h3>';
        echo '</header>';
        if ( method_exists($e, 'getContext') ) {
            echo 'Debug:';
            !d( $e->getContext() );
        }
    }
915140
protected function convertValidationExceptionToEntityException(ValidationException $e): UnprocessableEntityException
    {
        return new UnprocessableEntityException(Arr::first(Arr::first($e->errors())));
    }
257898
protected function handleException($passable, Exception $e)
    {
        if (! $this->container->bound(ExceptionHandlerContract::class) ||
            ! $passable instanceof DataProviderContract) {
            throw $e;
        }

        $handler = $this->container->make(ExceptionHandlerContract::class);

        $handler->report($e);

        $response = $handler->render($passable, $e);

        if (method_exists($response, 'withException')) {
            $response->withException($e);
        }

        return $response;
    }
611270
private function exception(ProcessorException $e)
	{

		$data = array(
			'type'    => Type::ERROR,
			'code'    => $e->getCode(),
			'message' => $e->getMessage(),
			'time'    => Time::ts(),
		);
		$this->response = new Response($data, Type::ERROR, null);

		return $this->response;

	}
358903
public static function fromError(\Error $e)
    {
        return new self($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e);
    }