| 1 | import { Schema } from "effect" |
| 2 | |
| 3 | export class UserNotFound extends Schema.TaggedError<UserNotFound>()( |
| 4 | "UserNotFound", |
| 5 | {}, |
| 6 | // You can specify the status code for this error inline |
| 7 | { httpApiStatus: 404 } |
| 8 | ) {} |
| 9 | |
| 10 | export class SearchQueryTooShort |
| 11 | extends Schema.TaggedError<SearchQueryTooShort>()("SearchQueryTooShort", {}, { httpApiStatus: 422 }) |
| 12 | { |
| 13 | static readonly minimumLength = 2 |
| 14 | } |
| 15 | |
| 16 | // Create a wrapper error class for all errors in the Users API. |
| 17 | // |
| 18 | // This prevents adding too many error types to services / endpoint definitions. |
| 19 | // |
| 20 | export class UsersError extends Schema.TaggedError<UsersError>()("UsersError", { |
| 21 | reason: Schema.Union([UserNotFound, SearchQueryTooShort]) |
| 22 | }) {} |