-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
55 lines (43 loc) · 1.4 KB
/
errors.go
File metadata and controls
55 lines (43 loc) · 1.4 KB
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
package main
import (
"fmt"
"net/http"
"time"
)
const CANT_CREATE_SITE_ERROR = `Oopsie daisy!
Can't create a new site. It's not your fault.
Please try again in a few seconds or contact codumentary.com@gmail.com for help
`
type ApiError struct {
Message string
StatusCode int
}
// NewApiError returns an ApiError with the the message made from the format string.
func NewApiError(statusCode int, format string, a ...interface{}) error {
return &ApiError{
Message: fmt.Sprintf(format, a...),
StatusCode: statusCode,
}
}
func (error *ApiError) Error() string {
return error.Message
}
func InvalidDelayError(rawDelay string) error {
return NewApiError(http.StatusBadRequest,
"Oopsie daisy! Could not convert delay <%s> to float.", rawDelay)
}
func DelayIsTooBigError(delay time.Duration) error {
return NewApiError(http.StatusBadRequest,
"Oopsie daisy! Delay can't be greater than %s, got delay %s",
MAX_DELAY, delay)
}
func CantChangeBuiltinSiteError() error {
return NewApiError(http.StatusForbidden, "Oopsie daisy! You can't change builtin sites.")
}
func UnknownSiteError(site string) error {
return NewApiError(http.StatusNotFound, "Oopsie daisy! Site <%s> doesn't exist.", site)
}
// TODO: rename to CantGenerateUniqueSiteNameError? (It is used in server.generateUniqueSiteName)
func CantCreateSiteError() error {
return NewApiError(http.StatusInternalServerError, CANT_CREATE_SITE_ERROR)
}