Moved away from local files to complete database driven articles
This commit is contained in:
21
api/error.go
Normal file
21
api/error.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
DatabaseError = ApiError{Message: "internal database error", Code: http.StatusInternalServerError}
|
||||
InvalidJson = ApiError{Message: "invalid json", Code: http.StatusUnprocessableEntity}
|
||||
)
|
||||
|
||||
type ApiError struct {
|
||||
Message string `json:"message"`
|
||||
Code int
|
||||
}
|
||||
|
||||
func (ae ApiError) Send(w http.ResponseWriter) error {
|
||||
w.WriteHeader(ae.Code)
|
||||
return json.NewEncoder(w).Encode(ae)
|
||||
}
|
||||
Reference in New Issue
Block a user