2019-07-18 14:10:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2019-07-18 15:15:19 +00:00
|
|
|
"github.com/nxshock/signaller/models"
|
2019-07-18 14:10:43 +00:00
|
|
|
)
|
|
|
|
|
2019-07-18 15:15:19 +00:00
|
|
|
func errorResponse(w http.ResponseWriter, code models.ApiError, httpCode int, message string) {
|
2019-07-18 14:10:43 +00:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
if message != "" {
|
|
|
|
code.Message = message
|
|
|
|
}
|
|
|
|
|
|
|
|
w.WriteHeader(httpCode)
|
|
|
|
w.Write(code.JSON())
|
|
|
|
}
|
|
|
|
|
2019-07-18 15:15:19 +00:00
|
|
|
func NewError(code models.ApiError, message string) *models.ApiError {
|
2019-07-18 14:10:43 +00:00
|
|
|
if message != "" {
|
|
|
|
code.Message = message
|
|
|
|
}
|
|
|
|
|
|
|
|
return &code
|
|
|
|
}
|