-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy patherrors.go
40 lines (33 loc) · 892 Bytes
/
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
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package x
import (
"net/http"
"github.com/ory/fosite"
"github.com/ory/x/logrusx"
)
var (
ErrNotFound = &fosite.RFC6749Error{
CodeField: http.StatusNotFound,
ErrorField: http.StatusText(http.StatusNotFound),
DescriptionField: "Unable to locate the requested resource",
}
ErrConflict = &fosite.RFC6749Error{
CodeField: http.StatusConflict,
ErrorField: http.StatusText(http.StatusConflict),
DescriptionField: "Unable to process the requested resource because of conflict in the current state",
}
)
func LogError(r *http.Request, err error, logger *logrusx.Logger) {
if logger == nil {
logger = logrusx.New("", "")
}
logger.WithRequest(r).
WithError(err).Errorln("An error occurred")
}
func Must[T any](t T, err error) T {
if err != nil {
panic(err)
}
return t
}