-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
36 lines (29 loc) · 888 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
package harper
import (
"errors"
"fmt"
"strings"
)
type OperationError struct {
StatusCode int
Message string
}
func (e *OperationError) Error() string {
return fmt.Sprintf("%s (%d)", e.Message, e.StatusCode)
}
func (e *OperationError) IsAlreadyExistsError() bool {
return e.StatusCode > 399 && strings.Contains(e.Message, "already exists")
}
func (e *OperationError) IsDoesNotExistError() bool {
return e.StatusCode > 399 && strings.Contains(e.Message, "does not exist")
}
func (e *OperationError) IsNotAuthorizedError() bool {
return e.StatusCode == 403
}
var (
ErrJobStatusUnknown = errors.New("unknown job status")
ErrJobNotFound = errors.New("job not found")
ErrNoRows = errors.New("did not return any rows")
ErrTooManyRows = errors.New("did return more than one row")
ErrNotSingleColumn = errors.New("expected a single column return")
)