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
After lots of time spend browsing the internet, I cannot seem to find a recommended approach to type error responses returned from a REST API. Let's say a REST API always returns an error in the following format:
Using Typescript I would like to indicate that in case of an error this is the expected shape of it. Now, I understand it is not as simple, because if let's say the REST API is unreachable, there is still going to be an Axios error, but it will not follow this pattern as in that case it would not be generated by the said REST API.
All these things considered, could you kindly suggest good ways to solve this problem?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
After lots of time spend browsing the internet, I cannot seem to find a recommended approach to type error responses returned from a REST API. Let's say a REST API always returns an error in the following format:
Using Typescript I would like to indicate that in case of an error this is the expected shape of it. Now, I understand it is not as simple, because if let's say the REST API is unreachable, there is still going to be an Axios error, but it will not follow this pattern as in that case it would not be generated by the said REST API.
All these things considered, could you kindly suggest good ways to solve this problem?
Grateful,
V.R.
Beta Was this translation helpful? Give feedback.
All reactions