Commit | Line | Data |
---|---|---|
5fb5cef1 | 1 | use MooseX::Declare; |
2 | ||
3 | role CatalystX::Declare::Action::CatchValidationError { | |
4 | ||
5 | use TryCatch; | |
6 | ||
7 | around execute (Object $controller, Object $ctx, @rest) { | |
8 | ||
9 | try { | |
10 | $self->$orig($controller, $ctx, @rest); | |
11 | } | |
12 | catch (Str $error where { /^Validation failed for/ }) { | |
13 | ||
14 | $ctx->response->body( 'Bad Request' ); | |
15 | $ctx->response->status( 400 ); | |
16 | $ctx->detach; | |
17 | } | |
18 | catch (Any $other) { | |
19 | ||
20 | die $other; | |
21 | } | |
22 | ||
23 | return 1; | |
24 | } | |
25 | } |