The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PONAPI::Exception - Exceptions for PONAPI::Server

VERSION

version 0.003003

SYNOPSIS

    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,
    );

DESCRIPTION

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.

The human-readable message for all of those will end up in the error response returned to the user.

METHODS

message

This attribute contains the exception message.

as_string

Returns a stringified form of the exception. The object is overloaded to return this if used in string context.

as_response

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 } ] } )

json_api_version

Defaults to 1.0; only used in as_response.

status

HTTP Status code for the exception; in most cases you don't need to set this manually.

AUTHORS

  • Mickey Nasriachi <mickey@cpan.org>

  • Stevan Little <stevan@cpan.org>

  • Brian Fraser <hugmeir@cpan.org>

COPYRIGHT AND LICENSE

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.