-
Notifications
You must be signed in to change notification settings - Fork 232
/
errors.go
91 lines (72 loc) · 2.69 KB
/
errors.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package authhandler
import (
"encr.dev/pkg/errors"
)
const authLink = "For more information on auth handlers and how to define them, see https://encore.dev/docs/develop/auth"
var (
errRange = errors.Range(
"authhandler",
`hint: valid signatures are:
- func(ctx context.Context, p *Params) (auth.UID, error)
- func(ctx context.Context, p *Params) (auth.UID, *UserData, error)
- func(ctx context.Context, token string) (auth.UID, error)
- func(ctx context.Context, token string) (auth.UID, *UserData, error)
note: *Params and *UserData are custom data types you define
`+authLink,
errors.WithRangeSize(20),
)
errInvalidNumberParameters = errRange.Newf(
"Invalid auth handler Signature",
"The auth handler must have exactly 2 parameters, found %d.",
)
errInvalidNumberResults = errRange.Newf(
"Invalid auth handler Signature",
"The auth handler must have 2 or 3 result parameters, found %d.",
)
errInvalidFirstParameter = errRange.New(
"Invalid auth handler Signature",
"The first parameter must be a context.Context.",
)
ErrInvalidAuthSchemaType = errRange.New(
"Invalid auth handler Signature",
"The second parameter must be a string or a pointer to a named struct.",
)
errInvalidFirstResult = errRange.New(
"Invalid auth handler Signature",
"The first result must be of type auth.UID.",
)
errInvalidSecondResult = errRange.New(
"Invalid auth handler Signature",
"The second result must be a pointer to a named struct.",
)
errCannotCallFromAnotherPackage = errRange.New(
"Invalid auth handler usage",
"You can not directly call an auth handler from another package.",
errors.WithDetails(authLink),
)
errInvalidReference = errRange.New(
"Invalid auth handler usage",
"Auth handlers can only be called, but not referenced.",
errors.WithDetails(authLink),
)
ErrInvalidFieldTags = errRange.New(
"Invalid auth payload",
"All fields used within an auth payload must originate from either an HTTP header, a query parameter, or a cookie.",
errors.WithDetails(
"You can specify them for each field using the struct tags, for example with `header:\"X-My-Header\"`, `query:\"my-query\", or `cookie:\"my-cookie\"`.\n\n"+
authLink,
),
)
ErrMultipleAuthHandlers = errRange.New(
"Multiple auth handlers found",
"Multiple auth handlers were found in the application. Encore only allows one auth handler to be defined per application.",
)
ErrNoAuthHandlerDefined = errRange.New(
"No Auth Handler Defined",
"An auth handler must be defined to use the auth directive on an API.",
errors.WithDetails(
"You can specify them for each field using the struct tags, for example with `header:\"X-My-Header\"` or `query:\"my-query\"`.\n\n"+
authLink,
),
)
)