-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherrors.go
More file actions
35 lines (28 loc) · 910 Bytes
/
errors.go
File metadata and controls
35 lines (28 loc) · 910 Bytes
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
package sqliteadmin
import (
"errors"
"fmt"
"net/http"
)
var (
ErrMissingTableName = errors.New("missing table name")
ErrMissingRow = errors.New("missing row")
ErrInvalidOrMissingIds = errors.New("invalid or missing ids")
ErrInvalidInput = errors.New("invalid input")
)
type APIError struct {
StatusCode int `json:"statusCode"`
Message string `json:"message"`
}
func (e APIError) Error() string {
return fmt.Sprintf("api error: %d, %s", e.StatusCode, e.Message)
}
func apiErrUnauthorized() APIError {
return APIError{StatusCode: http.StatusUnauthorized, Message: "Invalid credentials"}
}
func apiErrBadRequest(details string) APIError {
return APIError{StatusCode: http.StatusBadRequest, Message: "Bad request: " + details}
}
func apiErrSomethingWentWrong() APIError {
return APIError{StatusCode: http.StatusInternalServerError, Message: "Something went wrong"}
}