slugerrors.NewAuthorizationError   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
dl 0
loc 5
c 0
b 0
f 0
rs 10
nop 2
1
package slugerrors
2
3
type ErrorType struct {
4
	t string
5
}
6
7
var (
8
	ErrorTypeUnknown       = ErrorType{"unknown"}
9
	ErrorTypeAuthorization = ErrorType{"authorization"}
10
	ErrorTypeBadRequest    = ErrorType{"bad-request"}
11
	ErrorTypeNotFound      = ErrorType{"not-found"}
12
)
13
14
type SlugError struct {
15
	message   string
16
	slug      string
17
	errorType ErrorType
18
}
19
20
func (s SlugError) Error() string {
21
	return s.message
22
}
23
24
func (s SlugError) Slug() string {
25
	return s.slug
26
}
27
28
func (s SlugError) ErrorType() ErrorType {
29
	return s.errorType
30
}
31
32
func NewSlugError(errMsg string, slug string) SlugError {
33
	return SlugError{
34
		message:   errMsg,
35
		slug:      slug,
36
		errorType: ErrorTypeUnknown,
37
	}
38
}
39
40
func NewAuthorizationError(errMsg string, slug string) SlugError {
41
	return SlugError{
42
		message:   errMsg,
43
		slug:      slug,
44
		errorType: ErrorTypeAuthorization,
45
	}
46
}
47
48
func NewBadRequestError(errMsg string, slug string) SlugError {
49
	return SlugError{
50
		message:   errMsg,
51
		slug:      slug,
52
		errorType: ErrorTypeBadRequest,
53
	}
54
}
55
56
func NewNotFoundError(errMsg string, slug string) SlugError {
57
	return SlugError{
58
		message:   errMsg,
59
		slug:      slug,
60
		errorType: ErrorTypeNotFound,
61
	}
62
}
63