+
+ my %errors = (
+ session => { code => '401 Unauthorized', text => 'session expired' },
+ password => { code => '401 Unauthorized', text => 'incorrect username or password' },
+ action => { code => '400 Bad request', text => 'incorrect or missing action' },
+ access => { code => '403 Forbidden', text => 'no permissions for accessing this function' },
+ _default => { code => '500 Internal server error', text => 'general server-side error' },
+ );
+
+ my $error = $errors{$params{error}} // $errors{_default};
+ my $reply = SL::JSON::to_json({ status => 'failed', error => $error->{text} });
+
+ print $::request->cgi->header(
+ -type => 'application/json',
+ -charset => 'utf-8',
+ -status => $error->{code},
+ );
+
+ print $reply;
+
+ $self->end_request;
+}
+
+sub handle_login_error {
+ my ($self, %params) = @_;
+
+ return $self->reply_with_json_error(error => $params{error}) if $::request->type eq 'json';
+