> For the complete documentation index, see [llms.txt](https://docs.trustlesswork.com/trustless-work/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trustlesswork.com/trustless-work/v1-es/dapps-oss/escrow-lab/manejo-de-errores.md).

# Manejo de errores

## Resumen

Con estos métodos, comprobamos axios, la wallet y otros errores en las solicitudes de Trustless Work.

## Enums

Tipos de errores.

```typescript
/**
 * Tipos para tipos de Error
 */
export enum ApiErrorTypes {
  NOT_FOUND = "NOT_FOUND",
  UNAUTHORIZED = "UNAUTHORIZED",
  UNKNOWN_ERROR = "UNKNOWN_ERROR",
  WALLET_ERROR = "WALLET_ERROR",
}

```

## Manejar Errores

Lanzar los errores de la manera esperada.

```typescript
import axios from "axios";
import { AxiosError } from "axios";
import { ApiError } from "next/dist/server/api-utils";
import { ApiErrorTypes } from "../enums/error.enum";
import { ErrorResponse, WalletError } from "@/@types/errors.entity";

export const handleError = (error: AxiosError | WalletError): ErrorResponse => {
  if (axios.isAxiosError(error)) {
    const axiosError = error as AxiosError<ApiError>;
    const code = axiosError.response?.status || 500;
    const message = axiosError.response?.data?.message || error.message;
    return {
      message,
      code,
      type: mapStatusCodeToErrorType(code),
    };
  } else if (error.code === -4) {
    return {
      message: "La wallet se cerró antes de que la transacción fuera enviada",
      code: -4,
      type: ApiErrorTypes.WALLET_ERROR,
    };
  } else {
    return {
      message: error.message,
      code: 500,
      type: ApiErrorTypes.UNKNOWN_ERROR,
    };
  }
};

const mapStatusCodeToErrorType = (code: number): ApiErrorTypes => {
  switch (code) {
    case 404:
      return ApiErrorTypes.NOT_FOUND;
    case 401:
      return ApiErrorTypes.UNAUTHORIZED;
    default:
      return ApiErrorTypes.UNKNOWN_ERROR;
  }
};

```


---

# 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:

```
GET https://docs.trustlesswork.com/trustless-work/v1-es/dapps-oss/escrow-lab/manejo-de-errores.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
