Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Document how to handle 4XX or 5XX error codes in GraphQL loaders #69

Open
JulienPradet opened this issue Apr 30, 2019 · 0 comments
Open

Comments

@JulienPradet
Copy link
Contributor

WIP documentation for withDefault404Result

4XX or 5XX HTTP error codes are throwing errors when using axios. But this is not always the wanted behavior in a GraphQL schema. This is especially true for 404 errors that shouldn't throw but return null in a GraphQL resolver.

One can use withDefault404Result(promise, defaultResult) from node_modules/front-commerce/src/server/core/graphql/queryResponseBuilders.js to handle such case.

For instance, if you want to fetch a product but return null, you could do :

const {
  withDefault404Result
} = require("server/core/graphql/queryResponseBuilders");

const loadProduct = withDefault404Result(
  fetch(`/product/${sku}`).then(response => response.data),
  null
);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant