-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
39 lines (31 loc) · 1.02 KB
/
Copy patherrors.go
File metadata and controls
39 lines (31 loc) · 1.02 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
package main
import (
"fmt"
"net/http"
)
type HttpError struct {
Message string `json:"message"`
Code int `json:"code"`
}
func NewErrorInternalServerError(err error) *HttpError {
fmt.Println(err.Error())
return &HttpError{"Internal Server Error", http.StatusInternalServerError}
}
func NewErrorParamMissing(param string) *HttpError {
message := fmt.Sprintf("Required param \"%s\" missing", param)
return &HttpError{message, http.StatusBadRequest}
}
func NewErrorParamEmpty(param string) *HttpError {
message := fmt.Sprintf("param \"%s\" is empty", param)
return &HttpError{message, http.StatusBadRequest}
}
func NewErrorBadRequestError(message string) *HttpError {
return &HttpError{message, http.StatusBadRequest}
}
func NewErrorUnauthorizedError(message string) *HttpError {
return &HttpError{message, http.StatusUnauthorized}
}
func NewErrorBodyParseError(err error) *HttpError {
message := fmt.Sprintf("Error while parsing request body : \"%s\"", err.Error())
return &HttpError{message, http.StatusBadRequest}
}