X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=154b3d4ed44f6e7dcba8c3b6bda33393f6fc7fa3;hp=24674b95c50002ed73785f8f79fe98ab7d7d17b9;hb=f6ddb2f242a1635b4a5ba848f61d87c1093422dc;hpb=103f2d968b5a1a732c19c39ae03cdd9a44a96a4b diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 24674b9..154b3d4 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -3572,8 +3572,8 @@ sub setup_encoding { =head2 handle_unicode_encoding_exception Hook to let you customize how encoding errors are handled. By default -we just throw an exception. Receives a hashref of debug information. -Example of call: +we just throw an exception and the default error page will pick it up. +Receives a hashref of debug information. Example of call: $c->handle_unicode_encoding_exception({ param_value => $value, @@ -3581,8 +3581,12 @@ Example of call: encoding_step => 'params', }); -You can override this for custom handling of unicode errors. If you want a -custom response here, one approach is to throw an HTTP style exception: +It expects to receive a decoded string. + +You can override this for custom handling of unicode errors. By +default we just die. If you want a custom response here, one approach +is to throw an HTTP style exception, instead of returning a decoded +string or throwing a generic exception. sub handle_unicode_encoding_exception { my ($c, $params) = @_; @@ -3595,9 +3599,16 @@ in your application: sub handle_unicode_encoding_exception { my ($c, $params) = @_; $c->stash(BAD_UNICODE_DATA=>$params); + # return a dummy string. return 1; } +NOTE: Please keep in mind that once an error like this occurs, +the request setup is still ongoing, which means the state of C<$c> and +related context parts like the request and response may not be setup +up correctly (since we haven't finished the setup yet). If you throw +an exception the setup is aborted. + =cut sub handle_unicode_encoding_exception { @@ -3647,7 +3658,7 @@ sub _handle_param_unicode_decoding { $enc->decode( $value, $check); } catch { - $self->handle_unicode_encoding_exception({ + return $self->handle_unicode_encoding_exception({ param_value => $value, error_msg => $_, encoding_step => 'params',