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.

REST API does not throw HTTP error message/code

See original GitHub issue

When there is an HTTPError, the error object thrown does not contain any info about the error. For instance, creating a customer with an existing email like:

shopify.customer.create({
  first_name: 'John',
  last_name: 'Doe',
  email: 'alreadyexisting@email.com'
});

will throw the following error:

error HTTPError: Response code 422 (Unprocessable Entity) {
  name: 'HTTPError',
  code: undefined,
  timings: {
    start: 1614248835511,
    socket: 1614248835511,
    lookup: 1614248835691,
    connect: 1614248835728,
    secureConnect: 1614248835764,
    upload: 1614248835770,
    response: 1614248836439,
    end: 1614248836441,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 0,
      dns: 180,
      tcp: 37,
      tls: 36,
      request: 6,
      firstByte: 669,
      download: 2,
      total: 930
    }
  }
}

The code is undefined, error is undefined. Any workaround to access the errors that Shopify Admin API actually returns. In this case, the errors are:

{
    "errors": {
        "email": [
            "has already been taken"
        ]
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
lpincacommented, May 19, 2021

No plan at the moment. If it is requested by a consistent amount of users we might consider it.

1reaction
lpincacommented, Feb 25, 2021

Use error.response.body. Where error is your error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best Practices for REST API Error Handling - Baeldung
Learn about some of the best practices for handling REST API errors ... an HTTP status code of 500 when our BookNotFoundException is...
Read more >
Error handling for the REST API - BMC Documentation
When responding to requests, the REST API uses some of the HTTP ... 400, Bad Request, This code is used if the request...
Read more >
How implement error in Rest API? - php - Stack Overflow
There are a couple of concerns that you're dealing with in here. First one is error handling, whilst the second one is error...
Read more >
REST API error handling - IBM
The REST API reports errors by returning an appropriate HTTP response code, for example 404 (Not Found), and a JSON response. Any HTTP...
Read more >
Rails API Painless Error Handling and Rendering
What if I told you there was a way to abstract away messy and repetitive error raising and response rendering in your Rails...
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