Skip to content
This repository was archived by the owner on Dec 16, 2024. It is now read-only.
This repository was 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

@JulienPradet

Description

@JulienPradet

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
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions