Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch overflow errors on the client #386

Open
sofiaromorales opened this issue Apr 7, 2021 · 0 comments
Open

Catch overflow errors on the client #386

sofiaromorales opened this issue Apr 7, 2021 · 0 comments
Labels

Comments

@sofiaromorales
Copy link
Member

Description

When a user tries to create a payload with a value that overflows our DB scheme the app breaks.
Example: Trying to add a payment with a total amount bigger than Int 32bits (> 2147483647).
This scenario will probably never happen (at least the one of the example) but is a way to break the app so it has to be fixed.

The MySQL data types info can be found here

Possible solutions

There are two ways of resolving this:

  1. Let the user make the request and the using Apollo client handle the error and notify the user about it without breaking the app.
  2. Verify on the client the value of the variables before making certain requests, if the value would cause an overflow error in the DB, use UI elements to stop the client from making the request (disabling buttons, showing error messages...)

Research

After making some tests and researching it seems that there's a bug in the apollo client framework.
Following the doumentation the expected behavior should be the one described as follows,

Setting error policy to all, should allow me to catch the response error and access to the error` object returned by the promise with the error code and the server error message.

try {
            const newPayment = await createPayment({ variables })
            history.push(`/clients/${clientId}`)
        } catch (e) {
            console.log('e');
            console.log(e);
        }

I'm expecting to have access to those properties in the e variable

But the actual behavior is that e doesn't give access to the apollo client error object. But only returns a Network Error message. It seems that if the payload doesn't come with some data and an error status of 200 there's no access to the error object.

Similar problems found:

Test

  1. attempting to make a request that will cause an overflow error because of the Int size

Screen Shot 2021-04-07 at 1 27 19 PM

  1. The response of the server with the error message

Screen Shot 2021-04-07 at 1 28 44 PM

  1. Apollo throws an error without access to the error object

Screen Shot 2021-04-07 at 1 29 06 PM

Conclusion

I prefer that the solution of handling the error with Apollo client because is a lot cleaner than validating every request on the client before making it, so, if there's no way to get the error object from the request maybe is worthy to take a look on Apollo error links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant