NAME¶
WebAuth::Exception - Rich exception for errors from WebAuth API methods
SYNOPSIS¶
my $token;
my $wa = WebAuth->new;
eval {
$token = $wa->token_decode ($input);
# ...
};
if ($@ && ref ($@) eq 'WebAuth::Exception') {
my $e = $@;
print 'status: ', $e->status, "\n";
print 'message: ', $e->error_message, "\n";
print 'detail: ', $e->detail_message, "\n";
print "$e\n";
die $e->verbose_message;
}
DESCRIPTION¶
All WebAuth methods, and most methods in WebAuth::Key, WebAuth::Keyring,
WebAuth::KeyringEntry, and WebAuth::Token::* classes, will throw an exception
on error. Exceptions produced by the underlying C API call will be represented
by a WebAuth::Exception object.
You can use this object like you would normally use $@ and print it out or do
string comparisons with it and it will convert to the string representation of
the complete error message. But you can also access the structured data stored
inside the exception by treating it as an object and using the methods defined
below.
METHODS¶
- status ()
- Returns the WebAuth status code for the exception, which
will be one of the WebAuth::WA_ERR_* constants.
- error_message ()
- Returns the WebAuth error message. For most WebAuth
functions, this will consist of a generic error message followed by more
detail about this specific error in parentheses.
- detail_message ()
- Returns the "detail" message in the exception.
The detail message is additional information created with the exception
when it was raised and is usually the name of the WebAuth C function that
raised the exception.
- verbose_message ()
- Returns a verbose error message, which consists of all
information available in the exception, including the status code, error
message, line number and file, and any detail message in the
exception.
- to_string ()
- This method is called if the exception is interpolated into
a string. It is a wrapper around the verbose_message method.
- spaceship ([STRING], [SWAP])
- This method is called if the exception object is compared
to a string via cmp. It will compare the given string to the verbose error
message and return the result. If SWAP is set, it will reverse the order
to compare the given string to the verbose error.
AUTHORS¶
Roland Schemers and Russ Allbery <eagle@eyrie.org>.
SEE ALSO¶
WebAuth(3)
This module is part of WebAuth. The current version is available from
<
http://webauth.stanford.edu/>.