Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b9740e8a

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID b9740e8a9a77eafcaf7aacd530af23fa8dbcb9f9
  • Vorgänger de66b95f
  • Nachfolger 001c83b1

Error-Handling: Bei AJAX-Requests Fehler als JSON-Object zurückgeben

Unterschiede anzeigen:

SL/Dispatcher.pm
30 30
use SL::LXDebug;
31 31
use SL::LxOfficeConf;
32 32
use SL::Locale;
33
use SL::ClientJS;
33 34
use SL::Common;
34 35
use SL::Form;
35 36
use SL::Helper::DateTime;
......
74 75
  }
75 76
}
76 77

  
78
sub render_error_ajax {
79
  my ($error) = @_;
80

  
81
  SL::ClientJS->new
82
    ->error($error)
83
    ->render(SL::Controller::Base->new);
84
}
85

  
77 86
sub show_error {
78 87
  $::lxdebug->enter_sub;
79 88
  my $template             = shift;
......
85 94
  $::form->{error}         = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
86 95
  $::form->{error}         = $::locale->text('Incorrect password!')                    if ($error_type eq 'password');
87 96

  
97
  return render_error_ajax($::form->{error}) if $::request->is_ajax;
98

  
88 99
  $::form->header;
89 100
  print $::form->parse_html_template($template, \%params);
90 101
  $::lxdebug->leave_sub;
......
272 283
    1;
273 284
  } or do {
274 285
    if ($EVAL_ERROR ne END_OF_REQUEST) {
275
      print STDERR $EVAL_ERROR;
276
      $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
277
      chdir SL::System::Process::exe_dir;
278
      eval { show_error('generic/error') };
286
      my $error = $EVAL_ERROR;
287
      print STDERR $error;
288

  
289
      if ($::request->is_ajax) {
290
        eval { render_error_ajax($error) };
291
      } else {
292
        $::form->{label_error} = $::request->{cgi}->pre($error);
293
        chdir SL::System::Process::exe_dir;
294
        eval { show_error('generic/error') };
295
      }
279 296
    }
280 297
  };
281 298

  

Auch abrufbar als: Unified diff