2024-09-28 10:37:06 +00:00
|
|
|
package other
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2024-10-13 11:27:16 +00:00
|
|
|
// Return an error over an http connection.
|
|
|
|
// The error will have the given return code `code`
|
|
|
|
// and a json encoded body with the field "id" set to `errId`
|
|
|
|
// and a field "message" set to the `message`
|
|
|
|
func HttpErr(w http.ResponseWriter, errId int, message string, code int) {
|
2024-09-28 10:37:06 +00:00
|
|
|
w.WriteHeader(code)
|
|
|
|
w.Header().Add("Content-Type", "application/json")
|
2024-10-13 11:27:16 +00:00
|
|
|
fmt.Fprintf(w, "{\"id\": %d, \"message\": \"%s\"}", errId, message)
|
2024-09-28 10:37:06 +00:00
|
|
|
}
|