Question

I'm attempting to make a web request using the Http service. The request is failing (as expected) and returning a 403. I would expect that the onError handler would execute, but it's not. An exception is thrown and never caught.

_http(url: '/widgets/shiny-trinket', method: 'PUT', data: 'some malformed data')
  .then((resp) => successHandler, 
  onError: (resp) {
    // why aren't we getting here?
    displayErrorMessage();
  });

The exception that's thrown (from the console):

Failed to load resource: the server responded with a status of 403 (Forbidden)
  http://localhost/widgets/shiny-trinket
Instance of '_XMLHttpRequestProgressEvent'

STACKTRACE:
null

Am I doing something wrong? Or is this a bug?

UPDATE

I've also tried the following, and it also doesn't work.

_http(url: '/widgets/shiny-trinket', method: 'PUT', data: 'some malformed data')
  .then((resp) => successHandler) 
  .catchError((e) {
    // why aren't we getting here?
    displayErrorMessage();
  });
Was it helpful?

Solution 2

This appears to be a bug. I've submitted a pull request here.

OTHER TIPS

I just tried the example from the question How do I get Geolocation API to work in Dartium? which produces a 403 error and the error message in catchError is printed.

window.navigator
  .geolocation.getCurrentPosition()
    ..then((pos) {

      window.alert(pos.toString());
    })
    ..catchError((PositionError error) {
      window.alert("Error code: ${error.code}, Error message: ${error.message}");
    })
    ..whenComplete(() => window.alert("complete"))
    ;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top