|
1 | 1 | package faucet |
2 | 2 |
|
3 | | -import "errors" |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | +) |
4 | 6 |
|
5 | | -var ( |
6 | | - // ErrMarshalPayload is returned when the faucet payload cannot be marshaled to JSON. |
7 | | - ErrMarshalPayload = errors.New("failed to marshal faucet payload") |
| 7 | +// ErrMarshalPayload is returned when the faucet payload cannot be marshaled to JSON. |
| 8 | +type ErrMarshalPayload struct { |
| 9 | + Err error |
| 10 | +} |
8 | 11 |
|
9 | | - // ErrCreateRequest is returned when the faucet request cannot be created. |
10 | | - ErrCreateRequest = errors.New("failed to create faucet request") |
| 12 | +// Error implements the error interface for ErrMarshalPayload |
| 13 | +func (e ErrMarshalPayload) Error() string { |
| 14 | + return fmt.Sprintf("failed to marshal faucet payload: %v", e.Err) |
| 15 | +} |
11 | 16 |
|
12 | | - // ErrSendRequest is returned when the faucet request cannot be sent. |
13 | | - ErrSendRequest = errors.New("failed to send POST request to faucet") |
| 17 | +// ErrCreateRequest is returned when the faucet request cannot be created. |
| 18 | +type ErrCreateRequest struct { |
| 19 | + Err error |
| 20 | +} |
14 | 21 |
|
15 | | - // ErrUnexpectedStatusCode is returned when the faucet responds with a non-200 status code. |
16 | | - ErrUnexpectedStatusCode = errors.New("unexpected faucet response status code") |
17 | | -) |
| 22 | +// Error implements the error interface for ErrCreateRequest |
| 23 | +func (e ErrCreateRequest) Error() string { |
| 24 | + return fmt.Sprintf("failed to create faucet request: %v", e.Err) |
| 25 | +} |
| 26 | + |
| 27 | +// ErrSendRequest is returned when the faucet request cannot be sent. |
| 28 | +type ErrSendRequest struct { |
| 29 | + Err error |
| 30 | +} |
| 31 | + |
| 32 | +// Error implements the error interface for ErrSendRequest |
| 33 | +func (e ErrSendRequest) Error() string { |
| 34 | + return fmt.Sprintf("failed to send POST request to faucet: %v", e.Err) |
| 35 | +} |
| 36 | + |
| 37 | +// ErrUnexpectedStatusCode is returned when the faucet responds with a non-200 status code. |
| 38 | +type ErrUnexpectedStatusCode struct { |
| 39 | + Code int |
| 40 | +} |
| 41 | + |
| 42 | +// Error implements the error interface for ErrUnexpectedStatusCode |
| 43 | +func (e ErrUnexpectedStatusCode) Error() string { |
| 44 | + return fmt.Sprintf("unexpected faucet response status code: %d", e.Code) |
| 45 | +} |
0 commit comments