File Coverage

blib/lib/Whelk/Exception.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Whelk::Exception;
2             $Whelk::Exception::VERSION = '1.04';
3 20     20   11446 use Kelp::Base 'Kelp::Exception';
  20         47  
  20         143  
4              
5             # hint (string) to send to the user. App won't create a log if hint is present.
6             attr -hint => undef;
7              
8             1;
9              
10             __END__
11              
12             =pod
13              
14             =head1 NAME
15              
16             Whelk::Exception - Exceptions for your API
17              
18             =head1 SYNOPSIS
19              
20             use Whelk::Exception;
21              
22             # will set the status and log the body as error. A stock error message will
23             # be used in the response.
24             Whelk::Exception->throw(400, body => 'weird request got rejected because of reasons');
25              
26             # no log will be created, but the hint will be returned in the API response
27             Whelk::Exception->throw(403, hint => 'Access denied, not authorized');
28              
29             # fatal API error, will not return an API error page but rather regular
30             # text / html error page
31             Kelp::Exception->throw(500, body => 'Something went very, very wrong');
32              
33             =head1 DESCRIPTION
34              
35             Whelk::Exception is a tiny subclass of L<Kelp::Exception>. It introduces a
36             L</hint> attribute, which can be set to let the user know more about the error.
37             Much like Kelp exceptions, only 4XX and 5XX statuses are allowed.
38              
39             Whelk will treat Whelk::Exception differently than Kelp::Exception. Whelk
40             exceptions will be treated as planned API events and returned in API format.
41             Kelp exceptions will be thrown again, letting the Kelp application handle them,
42             which will result in plaintext or html error pages.
43              
44             =head1 ATTRIBUTES
45              
46             =head2 hint
47              
48             This is a hint for the API user. It must be a string and will be put into the
49             error response as-is. It will not be logged.
50