15370: Fix flaky test.
[arvados.git] / sdk / go / httpserver / error.go
index b222e18ea1159e67b9069c086207dbc3585c8e26..75ff85336fada402d3fab4dedece6f634f8aaed9 100644 (file)
@@ -6,9 +6,27 @@ package httpserver
 
 import (
        "encoding/json"
+       "fmt"
        "net/http"
 )
 
+func Errorf(status int, tmpl string, args ...interface{}) error {
+       return errorWithStatus{fmt.Errorf(tmpl, args...), status}
+}
+
+func ErrorWithStatus(err error, status int) error {
+       return errorWithStatus{err, status}
+}
+
+type errorWithStatus struct {
+       error
+       Status int
+}
+
+func (ews errorWithStatus) HTTPStatus() int {
+       return ews.Status
+}
+
 type ErrorResponse struct {
        Errors []string `json:"errors"`
 }