Skip to content

Commit

Permalink
added status func
Browse files Browse the repository at this point in the history
  • Loading branch information
cateiru committed Aug 8, 2021
1 parent 8e360ed commit d2ee0dd
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion status.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
package networkutil

import "net/http"
import (
"encoding/json"
"net/http"
)

type errorResponse struct {
StatusCode int `json:"status_code"`
Status string `json:"status"`
}

func ErrorStatus(w http.ResponseWriter) {
w.WriteHeader(http.StatusBadRequest)
}

func ErrorResponse(w http.ResponseWriter, statusCode int, err error) {
response := errorResponse{
StatusCode: statusCode,
Status: err.Error(),
}
responseText, err := json.Marshal(response)
if err != nil {
ErrorResponse(w, 1, err)
}

w.Write(responseText)
}

0 comments on commit d2ee0dd

Please sign in to comment.