Skip to content

[Fix] add Promise.reject() to useAppQuery if server returned 400>= #181

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wisniewski94
Copy link

WHY are these changes introduced?

If the server returns anything, useAppQuery will treat it as a success. It doesn't take into consideration the status code.
Example:

Server running express.js:

    if (!metafieldConfigKey?.body?.data?.shop?.metafield || !metafieldConfigSecret?.body?.data?.shop?.metafield) {
      res.status(404).send({});
      return;
    }

Frontend

    const response = useAppQuery({
        url: "/api/settings",
        reactQueryOptions: {
            onSuccess: async (response) => {
                const {
                    api_key,
                    confirmation_id,
                } = response[0];

                setValues((previousValues) => ({
                    ...previousValues,
                    api_key,
                    confirmation_id
                }));

                setIsLoading(false);
            },
            onError: async (response) => {
              console.log('error');
              setIsLoading(false);
            },
        },

    });

    console.log(response.isSuccess) // always returns true

WHAT is this pull request doing?

If the response status is not ok, it will return rejected promise with an error message containing the status code. The message should be improved

@wisniewski94 wisniewski94 changed the title [Fix] add Promise.reject() to useAppQuery if server returned 400> [Fix] add Promise.reject() to useAppQuery if server returned 400>= Apr 6, 2023
@wisniewski94
Copy link
Author

Bump 👀

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

Successfully merging this pull request may close these issues.

1 participant