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
Consider the following small modification of the UrlShortener example in the README:
urlshortener.url.get(params,(err,res)=>{if(err)returnconsole.error('The API returned an error: '+err);console.log(`Long url is ${res.data.longUrl}`);thrownewError('This error is not from the API');});
Expected behavior
The final error is bubbled up the stack and logged in the console.
Actual behavior
The final error is funneled back into my callback and treated as an API error:
Long url is https://www.google.com/
The API returned an error: Error: This error is not from the API
This seems to be a side effect of setting the callback as the catch() handler for the promise. The catch executes not only for errors resulting from the API call but also for any errors thrown in the then() handler for a successful call.
I'm not sure what Promise interface Axios supports, but I think the solution would be to set the callback as the error handler for a specific then(), instead of as a catch():
Consider the following small modification of the UrlShortener example in the README:
Expected behavior
The final error is bubbled up the stack and logged in the console.
Actual behavior
The final error is funneled back into my callback and treated as an API error:
This seems to be a side effect of setting the callback as the
catch()
handler for the promise. The catch executes not only for errors resulting from the API call but also for any errors thrown in thethen()
handler for a successful call.I'm not sure what Promise interface Axios supports, but I think the solution would be to set the callback as the error handler for a specific
then()
, instead of as acatch()
:The text was updated successfully, but these errors were encountered: