Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Exception message not transferred to response #24

@cxj

Description

@cxj

In \Relay\Middleware\ExceptionHandler\__invoke(), it attempts to place the exception message in the Response, but yet by the time Radar gets the Response back to call the Responder, the message has been overwritten. This results in a frustrating to debug HTTP 500 error with no further information.

Here's the stack at the try { in the above method:

ExceptionHandler.php:68, Relay\Middleware\ExceptionHandler->__invoke()
Runner.php:73, Relay\Runner->__invoke()
ResponseSender.php:40, Relay\Middleware\ResponseSender->__invoke()
Runner.php:73, Relay\Runner->__invoke()
Relay.php:60, Relay\Relay->__invoke()
Adr.php:138, Radar\Adr\Adr->run()
index.php:270, {main}()

Here's the relevant data at that same point:

$e = {ReflectionException} [8]
 message = "Class Clx\Domain\App\GetNpiData does not exist"
 *Exception*string = ""
 code = -1
 file = "/Users/chris/web2/vendor/aura/di/src/Resolver/Reflector.php"
 line = 77
 *Exception*trace = {array} [21]
 *Exception*previous = null
$next = {Relay\Runner} [2]
 queue = {array} [0]
 resolver = {Radar\Adr\Resolver} [1]
$request = {Zend\Diactoros\ServerRequest} [13]
 attributes = {array} [0]
 cookieParams = {array} [2]
 parsedBody = {array} [0]
 queryParams = {array} [0]
 serverParams = {array} [25]
 uploadedFiles = {array} [0]
 method = "GET"
 requestTarget = null
 uri = {Zend\Diactoros\Uri} [9]
 headers = {array} [10]
 headerNames = {array} [10]
 protocol = "1.1"
 stream = {Zend\Diactoros\PhpInputStream} [4]
$response = {Zend\Diactoros\Response} [7]
 phrases = {array} [65]
 reasonPhrase = ""
 statusCode = 200
 headers = {array} [0]
 headerNames = {array} [0]
 protocol = "1.1"
 stream = {Zend\Diactoros\Stream} [2]

Note that the correct exception message regarding the missing class is present at this point inside the exception object.

But then this line in the catch is called:

            $response = $this->exceptionResponse->withStatus(500);

Here's that method from \Zend\Diactoros\Response:

    public function withStatus($code, $reasonPhrase = '')
    {
        $new = clone $this;
        $new->setStatusCode($code);
        $new->reasonPhrase = $reasonPhrase;
        return $new;
    }

Note that it overwrites the reasonPhrase with an empty string if no second argument is passed to the method call.

I think that Relay\Middleware\ExceptionHandler\__invoke() should probably be passing $e->message like this to withStatus(500, $e->getMessage()).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions