internal/common/slugerrors/errors.go   A
last analyzed

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 37
dl 0
loc 60
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A slugerrors.NewAuthorizationError 0 5 1
A slugerrors.SlugError.ErrorType 0 2 1
A slugerrors.SlugError.Error 0 2 1
A slugerrors.SlugError.Slug 0 2 1
A slugerrors.NewBadRequestError 0 5 1
A slugerrors.NewNotFoundError 0 5 1
A slugerrors.NewSlugError 0 5 1
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