question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Error Handling for Network Errors

See original GitHub issue

Lets say I have a GraphQL schema defined has below,

input User {
     name: String!
     email: String!
}

type Mutation {
     createUser (payload: User!): Boolean
}

When I send a mutation createUser with input field/s missing, the server sends me a 400 Bad Request with some payload like below (as seen on browser Inspect logs),

{
  "errors": [
    {
      "message": "Field User.name of required type String! was not provided.",
      "locations": [
        {
          "line": 2,
          "column": 10
        }
      ]
    }
  ]
}

But Playground shows be the below error, and Apollo Client also receives this error.

{
  "error": "Response not successful: Received status code 400"
}

Is there a way to customise this error, maybe something like below,

{
    "errors": {
          "name": "ValidationError",
          "details": [
              "Field User.name of required type String! was not provided."
          ]
     }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
nagmancommented, May 9, 2018

Same here. How to display this payload in the server response body?

3reactions
frandioxcommented, May 9, 2018

Same here when creating a custom scalar.

In the network tab I can see {"errors":[{"message":"Expected type ReferenceNumber!, found \"12345678\"; String's length must be at most 7, got 8","locations":[{"line":2,"column":69}]}]}.

In the playground I only see {"error": "Response not successful: Received status code 400"}.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Handling for Network Requests in Client-Side JavaScript ...
Using Custom JavaScript Errors to classify our errors and build advanced logic in the event of a failure. Resources. Postman. A popular request ......
Read more >
Handling operation errors - Apollo GraphQL Docs
Apollo Client helps you handle these errors according to their type, enabling you to show appropriate information to the user when an error...
Read more >
Fetch - Error Handling for Failed HTTP Responses and ...
A quick example of how to handle both network errors and HTTP errors (4xx or 5xx) for fetch requests in a single catch...
Read more >
Error Handling with Combine and SwiftUI - Peter Friese
Learn how you can use Combine to improve error handling in your SwiftUI apps.
Read more >
Custom Error Handling for Network Errors · Issue #304 - GitHub
Lets say I have a GraphQL schema defined has below, input User { name: String! email: String! } type Mutation { createUser (payload:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found