Skip to content

Errors

When a request fails, the mock responds with a commercetools-style error body and an appropriate HTTP status code, so error-handling code in your integration is exercised the same way it would be against the real API.

Internally, errors are represented by CommercetoolsError, which carries:

FieldTypeDescription
messagestringHuman-readable message.
statusCodenumberHTTP status (defaults to 400).
infoBaseErrorThe primary error object.
errorsBaseError[]Additional error details.

Errors are serialised to the standard commercetools error envelope:

{
"statusCode": 400,
"message": "",
"errors": [
{ "code": "", "message": "" }
]
}

Unexpected (non-CommercetoolsError) failures return 500 with an error field.

SituationStatusNotes
Malformed where predicate400InvalidInput.
expand target not found400/404ReferencedResourceNotFound.
Update on missing resource404ResourceNotFound.
Missing/unknown token (when validateCredentials)401invalid_token. See Authentication.
Bad customer credentials (password grant)400invalid_customer_account_credentials.
Missing Basic auth on /oauth401invalid_client.
Unsupported grant type400unsupported_grant_type.

Because the SDK throws on non-2xx responses, you can assert on the thrown error in your tests:

await expect(fetchMissingCustomer()).rejects.toMatchObject({
statusCode: 404,
})