3 SGN::Exception - expressive exception object for web applications
7 die SGN::Exception->new(
9 title => 'Froozle Error',
10 public_message => "Cannot process the froozle.",
11 developer_message => "Froozle was '$froozle', path was '$fogbat_path'.",
17 # developers need to be notified that this happened
24 The SGN::Exception object is meant to hold a wide variety of
25 information about the nature of an exception or error condition.
26 Nearly all the attributes of the exception object are optional.
30 package SGN
::Exception
;
34 # make catalyst use this exception class
36 $Catalyst::Exception
::CATALYST_EXCEPTION_CLASS
= __PACKAGE__
;
39 with
'Catalyst::Exception::Basic';
49 All attributes are read-only. None are required.
53 String, publicly-visible message for this error. Should not reveal
54 details that could have security implications.
58 has
'public_message' => (
63 =head2 developer_message
65 String, private message for developers. Should be included in error
66 notifications sent to developers, debug backtraces, etc.
70 has
'developer_message' => (
75 #TODO: redundant, deleteme
76 has
'explanation' => (
83 Optional string, user-visible title for the exception as presented to the user.
92 =head2 is_server_error
94 Boolean, true if this error indicates a problem on the server side.
96 Defaults to true most of the time, but defaults to false if
97 is_client_error is explicitly set to true.
101 has
'is_server_error' => (
107 =head2 is_client_error
109 Boolean, true if this error indicates a problem on the client side.
111 Defaults to false most of the time, but default to true if
112 is_server_error is set and false.
116 has
'is_client_error' => (
124 Explicitly set the status code of the HTTP response for this error
127 Defaults to 500 (Internal Server Error) if is_server_error is set,
128 else 400 (Bad Request) if is_client_error is set, or 200 (OK) if
129 is_client_error and is_server_error are both false.
133 has
'http_status' => (
138 $self->is_server_error ?
500 :
139 $self->is_client_error ?
400 :
146 Flag indicating whether developers should be actively notified that
147 this exception occurred.
149 Boolean, defaults to true if is_server_error is set, false otherwise.
157 ); sub _build_notify
{
158 shift->is_server_error
161 around
'BUILDARGS' => sub {
164 my %args = @_ > 1 ?
@_ : ( message
=> @_ );
166 $args{developer_message
} ||= $args{message
};
167 $args{message
} ||= $args{developer_message
} || $args{public_message
} || '(no message)';
169 if( defined $args{is_client_error
} && !$args{is_client_error
} ) {
170 $args{is_server_error
} = 1 unless defined $args{is_server_error
};
172 if( defined $args{is_server_error
} && !$args{is_server_error
} ) {
173 $args{is_client_error
} = 1 unless defined $args{is_client_error
};
175 if( $args{is_client_error
} && ! defined $args{is_server_error
} ) {
176 $args{is_server_error
} = 0;
179 return $class->$orig( %args );
186 Return a plaintext string representation of this exception, suitable
187 for display in consoles and so forth.
194 ($self->public_message || '') . "\n"
195 .'Developer message: '
196 .($self->developer_message || 'none');
199 __PACKAGE__
->meta->make_immutable;