blob: 141e9fa101d8f342a4709ec172647ab60802e4cf [file]
package common
import (
"encoding/json"
"net/http"
"strconv"
)
func WriteError(w http.ResponseWriter, reason string, errorCode int, statusCode int) {
w.WriteHeader(statusCode)
resp := ErrorResponse{
ResponseCode: strconv.Itoa(errorCode),
ResponseMessage: reason,
StatusCode: statusCode,
}
bytes, err := json.Marshal(resp)
if err != nil {
w.Write([]byte("unable to marshal errorResponse: " + err.Error()))
} else {
w.Write(bytes)
}
}