Yukki::Error - Yukki's exception class
version 0.991_004
Yukki::Error->throw("Something really bad.", { ... });
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:
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.
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('message', { status => 'InternalServerError', show_stask_trace => 0, });
Constructs the exception (via "http_exception") and throws it.
Renders the HTML body for the error.
Setup the HTTP headers.
Returns the message.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
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.
To install Yukki, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yukki
CPAN shell
perl -MCPAN -e shell install Yukki
For more information on module installation, please visit the detailed CPAN module installation guide.