New srverrors package added. New error handling added to control package
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package srverrors
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServerErrMessage struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
func WriteErrorResponse(statusCode int, reasonMsg string, res http.ResponseWriter) {
|
||||
respBody := ServerErrMessage{}
|
||||
respBody.Reason = reasonMsg
|
||||
bb, _ := json.Marshal(respBody)
|
||||
res.Header().Add("Content-Type", "application/json; charset=utf-8")
|
||||
res.WriteHeader(statusCode)
|
||||
_, _ = res.Write(bb)
|
||||
}
|
||||
Reference in New Issue
Block a user