PONAPI::Exception - Exceptions for PONAPI::Server
version 0.003003
use PONAPI::Exception; PONAPI::Exception->throw( message => "Generic exception" ); PONAPI::Exception->throw( message => "Explanation for the sql error, maybe $DBI::errstr", sql => 1, ); PONAPI::Exception->throw( message => "Data had type `foo` but we wanted `bar`", bad_request_data => 1, );
PONAPI::Exception can be used by repositories to signal errors; exceptions thrown this way will be caught by the DAO and handled gracefully.
Different kinds of exceptions can be thrown by changing the arguments to throw; sql => 1 will throw a SQL exception, bad_request_data => 1 will throw an exception due to the input data being wrong, and not passing any of those will throw a generic exception.
throw
sql => 1
bad_request_data => 1
The human-readable message for all of those will end up in the error response returned to the user.
message
This attribute contains the exception message.
Returns a stringified form of the exception. The object is overloaded to return this if used in string context.
Returns the exception as a 3-element list that may be fed directly to plack as a {json:api} response.
$e->as_response; # ( $status, [], { errors => [ { detail => $message } ] } )
Defaults to 1.0; only used in as_response.
as_response
HTTP Status code for the exception; in most cases you don't need to set this manually.
Mickey Nasriachi <mickey@cpan.org>
Stevan Little <stevan@cpan.org>
Brian Fraser <hugmeir@cpan.org>
This software is copyright (c) 2019 by Mickey Nasriachi, Stevan Little, Brian Fraser.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install PONAPI::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PONAPI::Server
CPAN shell
perl -MCPAN -e shell install PONAPI::Server
For more information on module installation, please visit the detailed CPAN module installation guide.