# GET Error Codes

### /error\_codes

```json
/error_codes/{error_code}
```

**Paths**

* `GET /error_codes` — returns **all** exposed error codes.
* `GET /error_codes/{error_code}` — returns the **message** for one specific code, or 404 if not found/blacklisted.

**Example Query:**

```
https://base-hedger82.rasa.capital/error_codes
```

See this [section ](https://docs.symm.io/liquidity-provider-documentation/building-a-solver-on-symmio/solver-error-codes)for more information about error codes.

## Error Codes Implementation (Rasa)

```python
@common_router.get(
    '/error_codes',
    responses={status.HTTP_200_OK: {"model": ErrorCodeResponseSchema}},
    response_model=ErrorCodeResponseSchema
)
async def get_all_error_codes():
    return {
        code: msg
        for code, msg in ErrorCodes.items()
        if code not in ErrorCodeBlackList
    }


@common_router.get(
    '/error_codes/{error_code}',
    responses={status.HTTP_200_OK: {"model": ErrorCodeResponseSchema}},
    response_model=ErrorCodeResponseSchema
)
async def get_error_message(error_code: int):
    msg = ErrorCodes.get(error_code)
    if msg is None or error_code in ErrorCodeBlackList:
        raise ErrorCodeResponse(
            status_code=404,
            error=ErrorInfoContainer.error_code_not_found
        )
    return {error_code: msg}

```

### Logic

**Imports**

```python
from share.error_codes import ErrorCodes       # a dict[int, str]
from db_tools.triggers.trigger_utils import ErrorCodeBlackList  # a set[int]
```

* `ErrorCodes` is your master map of all possible error‐code → message entries.
* `ErrorCodeBlackList` lists codes you don’t want to expose via the public API.

**GET /error\_codes**

* Filters out any blacklisted codes, then returns the rest as a plain dict.

**GET /error\_codes/{error\_code}**

* Looks up the message via `ErrorCodes.get(error_code)`.
* If missing or blacklisted, raises an `ErrorCodeResponse(404)`.
* Otherwise returns `{ error_code: message }`.

#### Steps to Implement Your Own Version

**Define the Error Codes**

```python
ErrorCodes = {
  1001: "Insufficient balance",
  1002: "Order timeout",
  # …
}
ErrorCodeBlackList = {9999, 8888}  # codes reserved for internal use
```

**Create the Response Schema**

```python
class ErrorCodeResponseSchema(RootModel[Dict[int, str]]):
    pass
```

**Define an Exception (example)**

```python
class ErrorCodeResponse(HTTPException):
    def __init__(self, status_code: int, error: ErrorInfoContainer):
        super().__init__(status_code=status_code, detail=error.to_dict())
```

**Add FastAPI Routes**

* In your `common_router`, register the two `@common_router.get` endpoints exactly as above.
* Import `ErrorCodes`, `ErrorCodeBlackList`, `ErrorCodeResponse`, and `ErrorCodeResponseSchema`.
