/
errors.go
67 lines (51 loc) · 1.4 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
package api
import (
"fmt"
"net/http"
"gopkg.in/gin-gonic/gin.v1"
)
type HttpError struct {
Code int
Err error
Type gin.ErrorType
}
func (e HttpError) Error() string {
return e.Err.Error()
}
func (e HttpError) Abort(c *gin.Context) {
c.AbortWithError(e.Code, e.Err).SetType(e.Type)
}
func NewHttpError(code int, err error, t gin.ErrorType) *HttpError {
return &HttpError{Code: code, Err: err, Type: t}
}
func NewNotFoundError() *HttpError {
return &HttpError{Code: http.StatusNotFound, Type: gin.ErrorTypePublic}
}
func NewBadRequestError(err error) *HttpError {
return NewHttpError(http.StatusBadRequest, err, gin.ErrorTypePublic)
}
func NewForbiddenError() *HttpError {
return &HttpError{Code: http.StatusForbidden, Type: gin.ErrorTypePublic}
}
func NewInternalError(err error) *HttpError {
return NewHttpError(http.StatusInternalServerError, err, gin.ErrorTypePrivate)
}
type FileNotFound struct {
Sha1 string
}
func (x FileNotFound) Error() string {
return fmt.Sprintf("File not found, sha1 = %s", x.Sha1)
}
type UpChainOperationNotFound struct {
FileID int64
opType string
}
func (x UpChainOperationNotFound) Error() string {
return fmt.Sprintf("Up chain operation %s not found for file_id %d", x.opType, x.FileID)
}
type CollectionNotFound struct {
CaptureID interface{}
}
func (x CollectionNotFound) Error() string {
return fmt.Sprintf("Collection not found, CaptureID = %s", x.CaptureID)
}