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

Error details not accessible for HTTP client #237

Closed
Boxonical opened this issue Aug 27, 2021 · 6 comments · Fixed by #252
Closed

Error details not accessible for HTTP client #237

Boxonical opened this issue Aug 27, 2021 · 6 comments · Fixed by #252

Comments

@Boxonical
Copy link

Issue summary

Shopify error code / details are not accessible in the .catch() method of HTTP clients, making debugging difficult & error handling impossible.

Sample HTTP response from Shopify:

{
  "errors": {
    "line_items": [
      "must have at least one line item"
    ]
  }
}

The error object in .catch():

{
    "message": "Received an error response (422 Unprocessable Entity) from Shopify: [object Object]. If you report this error, please include this id: 250f9792-8c43-4993-85e7-14c9659061a4",
    "code": 422,
    "statusText": "Unprocessable Entity"
}

Expected behavior

Perhaps a more meaningful error:

{
  "message": "Received an error response (422 Unprocessable Entity) from Shopify: [object Object]. If you report this error, please include this id: 250f9792-8c43-4993-85e7-14c9659061a4",
  "code": 422,
  "statusText": "Unprocessable Entity",
  "details": {
    "line_items": [
      "must have at least one line item"
    ]
  }
}

Actual behavior

[object Object] in error message comes from:
https://github.com/Shopify/shopify-node-api/blob/0ee4f8adb6260b552d447b8e03d8f34067a34e9a/src/clients/http_client/http_client.ts#L236-L238

Error thrown here:
https://github.com/Shopify/shopify-node-api/blob/0ee4f8adb6260b552d447b8e03d8f34067a34e9a/src/clients/http_client/http_client.ts#L251-L256

Steps to reproduce the problem

const { Shopify } = require('@shopify/shopify-api'),
	DOMAIN = '',
	API_KEY = '',
	API_SECRET_KEY = '',
	ACCESS_TOKEN = ''

Shopify.Context.initialize({
	API_KEY,
	API_SECRET_KEY,
	SCOPES: ['write_orders'],
	HOST_NAME: 'localhost',
	IS_EMBEDDED_APP: false,
	IS_PRIVATE_APP: false,
	API_VERSION: '2021-07'
})

const client = new Shopify.Clients.Rest(DOMAIN, ACCESS_TOKEN)
client.post({
	path: 'orders',
	type: 'application/json',
	data: {
		order: {
			line_items: []
		}
	}
})
	.then(res => {
		console.log('res', res)
	})
	.catch(err => {
		// {
		//     "message": "Received an error response (422 Unprocessable Entity) from Shopify: [object Object]. If you report this error, please include this id: 250f9792-8c43-4993-85e7-14c9659061a4",
		//     "code": 422,
		//     "statusText": "Unprocessable Entity"
		// }
		console.log('err', err)
	})
@paulomarg
Copy link
Contributor

Hey @Boxonical, thanks for the very detailed issue! You raise a good point, we'll look into making that error information available in the response.

@govindrai
Copy link

#250 is facing the same issue and returns a 400 against the script_tags api

@govindrai
Copy link

govindrai commented Oct 21, 2021

Another issue #220 is similarly facing an obfuscated error message.

@cheezeburger
Copy link

Any news on how we can obtain a better error message? "statusText": "Unprocessable Entity" is simply too vague and hard to debug.

@customerhub
Copy link

Try looking at the response body in the catch error - like this:
try { await shopify.product.create(productData) } catch (error) { console.log(error.response.body); }
That will show you the more detailed error from Shopify.

@ferares
Copy link

ferares commented Dec 21, 2023

@customerhub that works! is that included in the docs somewhere?

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

Successfully merging a pull request may close this issue.

6 participants