Skip to content

Commit

Permalink
docs: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Feb 13, 2024
1 parent 86e1a8f commit f4eacf2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions documentation/docs/guides/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,33 @@ Error handling is a crucial part of any application. It is important to handle e


<FlowChart selected="ErrorHandler" />

## Error handling in Fuego

Fuego [controllers](./controllers) returns a value and an error. If the error is not `nil`, it means that an error occurred while processing the request. The error will be returned to the client as a JSON response.

The error type returned as JSON is `fuego.HTTPError`. It has a `Status` and a `Info` field. The `Status` field is an integer that represents the error code. The `Info` field is a string that contains a human-readable error message.

If your error implements `Status() int` and `Info()` methods, the error will include the status code and the error message in the `fuego.HTTPError` response.

```go
type MyCustomError struct {
Status int
Message string
}

func (e MyCustomError) Status() int {
return e.Status
}
```

## Default errors

Fuego provides a set of default errors that you can use in your application.

- `fuego.BadRequestError`: 400 Bad Request
- `fuego.UnauthorizedError`: 401 Unauthorized
- `fuego.ForbiddenError`: 403 Forbidden
- `fuego.NotFoundError`: 404 Not Found
- `fuego.ConflictError`: 409 Conflict
- `fuego.InternalServerError`: 500 Internal Server Error

0 comments on commit f4eacf2

Please sign in to comment.