Recommended approach for error handling #329
Unanswered
piedrahitapablo
asked this question in
Q&A
Replies: 1 comment
-
Hello, Juan Pablo |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
I'm using this SDK and I'm just wondering what's the recommended approach for error handling when a request fails.
I was checking the code and in this line I see that the JSON response is thrown if the status code is not in the 2xx range. Generally, this is a bad practice and makes things complicated for developers when handling errors since there's no way to check if they came from the Mercado Pago SDK or any other piece of code, and also, some information is lost (the status code for example).
I know I could wrap the SDK in a method and ensure the error came from Mercado Pago, but then I wouldn't have a way to know if the request failed because I did something wrong (4xx) or because there was an internal error in the Mercado Pago server (5xx).
Does anyone know a good way to handle these situations?
Beta Was this translation helpful? Give feedback.
All reactions