You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Catching errors from service calling external API #4182
How can I catch an error and the request made when calling a external API using services and loopback-connector-rest ? My purpose is to log the response's error in a different way than Loopback.
With my team, we would like to catch all the errors when calling an external API, even when the API is shutdown. But it seems that the error is catch before, in the reject prodiver.
Also, I want to get the request made to the external API but I don't know how to get it. All I can get it's the request from the controller method.
Thank for your response. I don't know why, but now I can catch the error. Maybe a wrong manipulation.
I will give it a try for the interceptor, I'll keep you in touch if i make some progress or not.
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.
Activity
dhmlau commentedon Nov 22, 2019
@bobby91560, are you calling the service from the controller? If yes, then you can wrap that call within a try-catch block?
raymondfeng commentedon Nov 22, 2019
If you are looking for a logging component, check out #4117
bobby91560 commentedon Nov 22, 2019
@dhmlau That's what I already do.
With my team, we would like to catch all the errors when calling an external API, even when the API is shutdown. But it seems that the error is catch before, in the reject prodiver.
Also, I want to get the request made to the external API but I don't know how to get it. All I can get it's the request from the controller method.
dhmlau commentedon Nov 22, 2019
It might make sense to use interceptor to get that information. @raymondfeng, WDYT?
FYI -
https://medium.com/loopback/learning-loopback-4-interceptors-part-1-global-interceptors-163a7c5701b9
https://medium.com/loopback/learning-loopback4-interceptors-part-2-class-and-method-level-interceptors-c80b401c16e4
bobby91560 commentedon Nov 22, 2019
Thank for your response. I don't know why, but now I can catch the error. Maybe a wrong manipulation.
I will give it a try for the interceptor, I'll keep you in touch if i make some progress or not.
Ps: Thanks for the links
bobby91560 commentedon Nov 25, 2019
@dhmlau I tried to use interceptor to get the request but it doesn't seem to work when using services and loopback-connector-rest.
I have this service :
And this Interceptor :
What did I miss ?
bobby91560 commentedon Dec 2, 2019
Hi,
I repeat the same question as above. Did you have some clues to achieve what I want ?
stale commentedon Dec 25, 2020
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the
CODEOWNERSfile at the top-level of this repository. This issue will be closed within 30 days of being stale.