-
Notifications
You must be signed in to change notification settings - Fork 142
Get request in error callback - 3.x #96
Comments
Good question. This seems to be one use case I did no think about. Kludgish way would be to store the current url in another middleware for the error callback. Better way would probably be if I added the current url to the $app->add(new Tuupola\Middleware\JwtAuthentication([
"secret" => "supersecretkeyyoushouldnotcommittogithub",
"error" => function ($response, $arguments) {
$url = $arguments["url"]; // Do something with the url
$data["status"] = "error";
$data["message"] = $arguments["message"];
return $response
->withHeader("Content-Type", "application/json")
->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
])); |
Currently I do the middleware dance like you proposed. 😄 |
Ideally the request should be added to the error callback. There seems to be no reason why it shouldn't and the code seems to be working fine if I hack the change in. |
I too would love to see the Request available in the error callback 👍 |
This is a workaround because changing the error handler signature would break BC. Removing the request in 3.x was an oversight on my part and it will most likely be put back in 4.x.
Changing the error handler signature would be a BC break. Putting |
I think this is OK until 4.0 |
I was about to post the same issue, but will leave a +1 for this instead. My use case is different, as I don't need the URL, but the accept-header from the request - to correctly format an API-response (JSON / XML). I can easily come up with a workaround (#155 doesn't solve my issue), but I feel like the "correct" way would be to have the request available. There are probably many other scenarios. ...just noticed the pull request regarding this: #141. |
* Pass request uri as an argument to error handler This is a workaround because changing the error handler signature would break BC. Removing the request in 3.x was an oversight on my part and it will most likely be put back in 4.x.
I try to implement following behaviour:
error
callback jumps in(At this point I would like to get the URL the user tries to access and store it via a flash message for example )
return $response->withRedirect($container->get("router")->pathFor("login"), 301);
The problem is that I can't access the Request from the
error
callback and thebefore
callback is only called when a token can be found and decoded.Any suggestions how this can be achieved?
The text was updated successfully, but these errors were encountered: