Skip to content

iOS: http client with xhr backend does not throw an error on timeout  #13592

@duydao

Description

@duydao

I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

On iOS 10.1 (simulator & device), the http client doesn't throw an error when a timeout. Observable operators .catch and .finally have no effect. This works in Chrome/safari on the same machine.

There is a workaround by listening to the timeout event like this:

https://github.com/angular/angular/blob/master/modules/%40angular/http/src/backends/xhr_backend.ts#L140-L148:

      _xhr.addEventListener('load', onLoad);
      _xhr.addEventListener('error', onError);
      _xhr.addEventListener('timeout', onError);

      _xhr.send(this.request.getBody());

      return () => {
        _xhr.removeEventListener('load', onLoad);
        _xhr.removeEventListener('error', onError);
        _xhr.removeEventListener('timeout', onError);
        _xhr.abort();

A similar bug was fixed for angular.js 1.6:
angular/angular.js@fdf8e0f

Expected behavior

The http client should throw an eror when a timeout occures, on any supported platform.

Minimal reproduction of the problem with instructions

import { Http } from '@angular/http';
...
// make a call to a location that runs into a timeout, e.g. invalid port
http.get('localhost:383838')
  .subscribe(function() {
    console.error('next will never get called on timeout');
  }, function(error) {
    // won't get called on timeout
    console.error('error will never get called on timeout');
  }, function() {
    // complete won't get called on timeout
    console.error('complete will never get called on timeout');
  })

What is the motivation / use case for changing the behavior?

This bug was fixed in AngularJS 1.6, see: angular/angular.js@fdf8e0f

Please tell us about your environment:

iOS 9 & 10
safari mobile app
cordova / ionic build for ios

  • Angular version: 2.0.X

2.3.1

  • Browser:

iOS 9.3.1 WKWebView
iOS 10.1 WKWebView
iOS 9.3.5 Safari
iOS 10.1 Safari

  • Language: [all | TypeScript X.X | ES6/7 | ES5]
    TypeScript 2.0.10

  • Node (for AoT issues): node --version = no AOT was used

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions