Report HTTP errors first, then handler errors, fixes #18088

When reporting errors, it is better to report HTTP errors first.  Only report handler errors if the request was otherwise successful.  If you report the HTTP error first you can react to it by inspecting the status code.  This avoids xhr responding with a JSON parse error because you happened to get a 504 (session expired or somesuch), then a redirect to a login string.  Parsing a login screen as json will naturally fail.  And that error is somewhat useless as it doesn't tell you why it failed (due to HTTP request failure).

The pull provided is just a quick and simple reorder of how errors are reported.