Angular http client retryWhen cannot catch the error on the caller

Angular http client retryWhen cannot catch the error on the caller



I have an Ionic 3 App where I use HttpClient and I have an API call which is a GET request to the server. When the first try fails I will call the retryWhen is something error goes on.


retryWhen



The problem is that I couldn't catch the error to the caller



Here is my service code below.


getDriverMeInfo()
return this.http.get(`$this.global.baseUrl/me`)
.retryWhen(err => err.delay(10000).take(10)) // Delay after 10 seconds when an error occured and retry maximum of 10 takes
.concat(Observable.throw(new Error('Retry limit exceeded!'))).toPromise()



The component code below which is the caller


async getDriverInfo()
try
const meDetails = await this.driverMe.getDriverMeInfo() // Get the profile information of the driver if
console.log(meDetails)
catch (err)
console.log(err) // This wouldn't catch the error on the HttpErrorResponse




The only thing I catch in the error is the Observable.throw(new Error('Retry limit exceeded!')) but the instance of HttpErrorResponse that will give me a status code or message why it failed can't be catch.


Observable.throw(new Error('Retry limit exceeded!'))


HttpErrorResponse



Appreciate if someone could help.
Thanks in advance.




1 Answer
1


getDriverMeInfo()

return this._http.get<any>(`$this.global.baseUrl/me`)
.retryWhen((err)=>

return err.scan((retryCount)=>
retryCount+=1;
if(retryCount<6)

console.log("retrying attemp: "+ retryCount);
return retryCount

else

throw(err)

,0).delay(10000)
)



and the component,


this.driverMe.getDriverMeInfo().subscribe(res=>
)






21 hours remaining :(

– KnowledgeSeeker
Sep 17 '18 at 2:54






Haha ok. I was kidding , let it comes whenever it is

– Sajeetharan
Sep 17 '18 at 2:56






You waited for this. Hahaha sorry btw. Thanks!

– KnowledgeSeeker
Sep 19 '18 at 0:23






Btw sometimes when the server return a response code of 500. It sais that err.scan is not a function.

– KnowledgeSeeker
Sep 19 '18 at 6:23






you can handle error in that case, stackoverflow.com/questions/45973295/…

– Sajeetharan
Sep 19 '18 at 8:47



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế