JSON.stringify breaks with type `new Error('...')` in http timeout


#1

I’m using a new Error statement in an http observable timeout, but then it generates error ‘JSON.stringify(err, null, 2)’ won’t show the error as expected:

 query_post_rest (url: string, json: any, headers?: Headers) {
    return new Promise((resolve, reject) => {
      headers = headers || new Headers();
      headers.append('Content-Type', 'application/json;charset=UTF-8');
      this.http.post(url, JSON.stringify(json), { headers: headers })
        .retry(2)
        .timeout(10000, new Error('Tiempo de espera alcanzado.'))
        .delay(10)
        .map((res) => res.json())
        .subscribe(
          (res) => resolve(res),
          (err) => {
            if (err.url === null) return reject('Servidor no disponible, apagado o fuera de servicio');
            return reject(err)
          }
        )
    })
}

Then in another service:

this.db.query_post_rest_auth(url, json)
.then((success) => {
  this.conf.showAlert({title: 'Backup Restaurado'})
})

.catch((err) => {
  console.error(err)
  this.conf.showAlert({
    title: 'Error restaurando backup',
    subTitle: 'Error generado:',
    template: JSON.stringify(err, null, 2)
  })
})