Added: downloading and returning wikipedia articles
This commit is contained in:
24
api/httpio/httperror.go
Normal file
24
api/httpio/httperror.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package httpio
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type HTTPError struct {
|
||||
StatusCode int `json:"-"`
|
||||
ErrorCode string `json:"error-code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (h HTTPError) Raise(w http.ResponseWriter) {
|
||||
jsonBytes, _ := json.Marshal(h)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(h.StatusCode)
|
||||
w.Write(jsonBytes)
|
||||
}
|
||||
|
||||
func RaiseOnlyStatusCode(w http.ResponseWriter, code int) {
|
||||
http.Error(w, "", code)
|
||||
}
|
||||
Reference in New Issue
Block a user