We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8e360ed commit d2ee0ddCopy full SHA for d2ee0dd
status.go
@@ -1,7 +1,28 @@
1
package networkutil
2
3
-import "net/http"
+import (
4
+ "encoding/json"
5
+ "net/http"
6
+)
7
+
8
+type errorResponse struct {
9
+ StatusCode int `json:"status_code"`
10
+ Status string `json:"status"`
11
+}
12
13
func ErrorStatus(w http.ResponseWriter) {
14
w.WriteHeader(http.StatusBadRequest)
15
}
16
17
+func ErrorResponse(w http.ResponseWriter, statusCode int, err error) {
18
+ response := errorResponse{
19
+ StatusCode: statusCode,
20
+ Status: err.Error(),
21
+ }
22
+ responseText, err := json.Marshal(response)
23
+ if err != nil {
24
+ ErrorResponse(w, 1, err)
25
26
27
+ w.Write(responseText)
28
0 commit comments