diff --git a/errorHttp.go b/errorHttp.go new file mode 100644 index 0000000..aebaa41 --- /dev/null +++ b/errorHttp.go @@ -0,0 +1,34 @@ +package main + +import ( + "encoding/json" + "net/http" +) + +type errorHTTPResponse struct { + ErrorMsg string + HTTPStatusCode int + HTTPHeader http.Header +} + +func (e errorHTTPResponse) Error() string { + return e.ErrorMsg +} + +func errorHTTPResponseNew(r *http.Response, msg string) (e errorHTTPResponse) { + e.ErrorMsg = msg + e.HTTPStatusCode = r.StatusCode + e.HTTPHeader = r.Header + return e +} + +type crmdReason struct { + Reason string `json:"reason"` + Data string `json:"data"` +} + +func (e *errorHTTPResponse) XStatusReason() (r crmdReason) { + jsonStr := e.HTTPHeader.Get("X-Status-Reason") + json.Unmarshal([]byte(jsonStr), &r) + return +} diff --git a/errorHttp_test.go b/errorHttp_test.go new file mode 100644 index 0000000..8695488 --- /dev/null +++ b/errorHttp_test.go @@ -0,0 +1,7 @@ +package main + +import "testing" + +func TestXStatusReason(t *testing.T) { + //TODO +}