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