forked from rpdg/vercel_blob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
64 lines (53 loc) · 1.48 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package vercel_blob
import (
"fmt"
)
// VercelBlobError will be the type of all errors raised by this crate.
type VercelBlobError struct {
Msg string
Code string
}
func (e VercelBlobError) Error() string {
return e.Msg
}
// All errors raised by this crate will be instances of VercelBlobError
var (
ErrNotAuthenticated = &VercelBlobError{
Msg: "No authentication token. Expected environment variable BLOB_READ_WRITE_TOKEN to contain a token",
Code: "not_authenticated",
}
ErrBadRequest = func(msg string) VercelBlobError {
return VercelBlobError{
Msg: fmt.Sprintf("Invalid request: %s", msg),
Code: "bad_request",
}
}
ErrForbidden = &VercelBlobError{
Msg: "Access denied, please provide a valid token for this resource",
Code: "forbidden",
}
ErrStoreNotFound = &VercelBlobError{
Msg: "The requested store does not exist",
Code: "store_not_found",
}
ErrStoreSuspended = &VercelBlobError{
Msg: "The requested store has been suspended",
Code: "store_suspended",
}
ErrBlobNotFound = &VercelBlobError{
Msg: "The requested blob does not exist",
Code: "not_found",
}
)
func NewUnknownError(statusCode int, message string) VercelBlobError {
return VercelBlobError{
Msg: fmt.Sprintf("Unknown error, please visit https://vercel.com/help (%d): %s", statusCode, message),
Code: "unknown_error",
}
}
func NewInvalidInputError(field string) VercelBlobError {
return VercelBlobError{
Msg: fmt.Sprintf("%s is required", field),
Code: "invalid_input",
}
}