NAME

Yukki::Error - Yukki's exception class

VERSION

version 0.99_01

SYNOPSIS

Yukki::Error->throw("Something really bad.", { ... });

DESCRIPTION

If you are familiar with HTTP::Throwable::Factory, this is similar to that (and is based on that).

However, there are two differences. First, the error message is given primacy rather than exception type, so you can just use this to throw an exception:

use Yukki::Error qw( http_throw );
http_throw('something went wrong');

Since you almost always want your exception to be an internal server error of some kind, this makes more sense to me than having to write:

use HTTP::Throwable::Factory qw( http_throw );
http_throw(InternalServerError => {
    message => 'something went wrong',
});

To specify the type of exception, us status:

use Yukki::Error qw( http_throw );
http_throw('something was not found', {
    status => 'NotFound',
});

The second difference is that all exceptions thrown by this factory inherit from Yukki::Error, so this works:

use Scalar::Util qw( blessed );
use Try::Tiny;
try { ... }
catch {
    if (blassed $_ && $_->isa("Yukki::Error") {
        # we now this is an application error from Yukki
    }
};

This makes it easy to know whether Yukki generated the exception or something else did.

EXPORTS

http_exception

my $error = http_exception('message', {
    status           => 'InternalServerError',
    show_stask_trace => 0,
});

Creates a new exception object. Calls the constructor for Yukki:Error and applied the HTTP::Throwable status role needed (prior to construction actually).

http_throw

http_throw('message', {
    status           => 'InternalServerError',
    show_stask_trace => 0,
});

Constructs the exception (via "http_exception") and throws it.

METHODS

body

Renders the HTML body for the error.

body_headers

Setup the HTTP headers.

as_string

Returns the message.

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Qubling Software LLC.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.