mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 05:32:20 +01:00
22 lines
373 B
Go
22 lines
373 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type ErrorBody struct {
|
|
Error string
|
|
}
|
|
|
|
func writeHTTPError(res http.ResponseWriter, err error) {
|
|
res.WriteHeader(400)
|
|
encodedOutput, err := json.Marshal(ErrorBody{Error: err.Error()})
|
|
if err != nil {
|
|
fmt.Println("Failed to generate HTTP error: " + err.Error())
|
|
} else {
|
|
res.Write(encodedOutput)
|
|
}
|
|
|
|
}
|