> For the complete documentation index, see [llms.txt](https://developer.esw.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.esw.com/returns-api/grp-returns-api/error-handling/error-schemas.md).

# Error Schemas

This API uses three error schemas. Two share the same field shape but are registered under different names in the spec. Always check which one is returned for a given endpoint and status code.

#### Schema 1 — `ProblemDetails`

Used for: `401`, `403`, `404`, `409`, `500` on most endpoints. Two aliases exist — `Microsoft.AspNetCore.Mvc.ProblemDetails` and `ProblemDetails` — both have identical structure.

```json
{
  "type": "string",
  "title": "string",
  "status": 401,
  "detail": "string",
  "instance": "string"
}
```

All fields nullable. `additionalProperties: {}` — extra fields may appear.

#### Schema 2 — `ValidationProblemDetails`

Used for: `400 Bad Request` on all endpoints that document it. Two aliases — `Microsoft.AspNetCore.Mvc.ValidationProblemDetails` and `ValidationProblemDetails` — both identical.

```json
{
  "errors": {
    "FieldName": ["Error message one.", "Error message two."],
    "nested.Field": ["Error message."]
  },
  "type": "string",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "detail": "string",
  "instance": "string"
}
```

The `errors` object is a **dictionary mapping field names to arrays of error strings**. This is not a flat array. Iterate the dictionary keys to read every validation message. All top-level fields nullable. `additionalProperties: {}`.

#### Schema 3 — `BaseResponse`

Used **only** for `500` on `GET /{identifier}/return-orders/{returnOrderNumber}/{documentType}`.

```json
{
  "userMessage": "string",
  "details": "string"
}
```

`additionalProperties: false` — no extra fields. This schema surfaces user-readable error detail, unlike the more technical `ProblemDetails`.

#### Universal Safe Parser

{% code expandable="true" %}

```javascript
async function parseGrpError(response) {
  const text = await response.text().catch(() => "");
  if (!text.trim()) {
    return { schema: "none", status: response.status };
  }

  let parsed;
  try {
    parsed = JSON.parse(text);
  } catch {
    return { schema: "unparseable", status: response.status, raw: text };
  }

  // BaseResponse: has userMessage/details, no title
  if ("userMessage" in parsed && !("title" in parsed)) {
    return {
      schema: "BaseResponse",
      status: response.status,
      userMessage: parsed.userMessage ?? null,
      details: parsed.details ?? null,
    };
  }

  // ValidationProblemDetails: has errors dict
  if ("errors" in parsed) {
    return {
      schema: "ValidationProblemDetails",
      status: response.status,
      errors: parsed.errors ?? {},
      title: parsed.title ?? null,
      detail: parsed.detail ?? null,
      type: parsed.type ?? null,
      instance: parsed.instance ?? null,
    };
  }

  // ProblemDetails
  return {
    schema: "ProblemDetails",
    status: response.status,
    title: parsed.title ?? null,
    detail: parsed.detail ?? null,
    type: parsed.type ?? null,
    instance: parsed.instance ?? null,
  };
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.esw.com/returns-api/grp-returns-api/error-handling/error-schemas.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
