Exceptions & Panic Recovery
HttpException, built-in exceptions, and the panic-recovery contract
gonest.HttpException is the base type every gonest exception embeds.
gonest.NewHttpException().
SetStatus(http.StatusBadRequest).
SetName("FooError").
SetMessage("lorem ipsum").
SetDetails(details)Any type embedding HttpException structurally satisfies the Exception
interface — the recovery layer uses a type-assertion, never a closed
type-switch.
Built-in exceptions
| Exception | Status |
|---|---|
NotFoundException | 404 |
BadRequestException | 400 |
ConflictException | 409 |
UnauthorizedException | 401 |
ForbiddenException | 403 |
Each has a New*Exception(details any) constructor.
Custom exceptions
Embed gonest.HttpException exactly like a built-in:
type FooError struct{ gonest.HttpException }
func NewFooError(details any) *FooError {
return &FooError{
HttpException: gonest.NewHttpException().
SetStatus(http.StatusBadRequest).
SetName("FooError").
SetMessage("lorem ipsum").
SetDetails(details),
}
}Panic → response contract
Any panic with a value satisfying Exception becomes
{"name": ..., "message": ..., "details": ...} JSON at that exception's own
status code. Any other panic (nil pointer, index out of range, etc.)
becomes a generic 500 with zero leaked internal detail — the process
never crashes.
HTTP status constants
gonest.HttpStatus* re-exports all 63 standard net/http.StatusXxx
constants under the gonest namespace (e.g. gonest.HttpStatusNotFound), so
handler code never needs to import net/http just for status codes.