Using something like HTTP::Exception for exception handling

36 views
Skip to first unread message

Robert Rothenberg

unread,
Nov 25, 2020, 11:49:37 AM11/25/20
to Mojolicious

Is there a mojo-equivalent to HTTP::Exception that will let be throw an exception with a specific HTTP response code?

Likewise, is a plugin or documented method for overriding the `reply.exception` helper to use a specific template/layout when there are errors?

Sebastian Riedel

unread,
Nov 25, 2020, 11:51:48 AM11/25/20
to Mojolicious
Likewise, is a plugin or documented method for overriding the `reply.exception` helper to use a specific template/layout when there are errors?

Robert Rothenberg

unread,
Nov 26, 2020, 4:12:51 AM11/26/20
to Mojolicious
That's helpful for customising the error pages. But how do I update the HTTP status code?

Robert Rothenberg

unread,
Nov 27, 2020, 3:54:33 AM11/27/20
to Mojolicious
I should be more specific. In a "before_render" method, overriding "status" in the arguments hash or in the stash does not actually change the status.  I'd like to be able to change the status from 500 to something else.

Robert Rothenberg

unread,
Dec 7, 2020, 5:19:06 AM12/7/20
to Mojolicious
As per discussion in https://github.com/mojolicious/mojo/issues/1622, one can use something like

     $c->reply->exception('Division by zero!')->rendered(400)
Reply all
Reply to author
Forward
0 new messages