Replace DAVError with HTTPError + Error
That way we can avoid having different ways of representing the same error value.
This commit is contained in:
@@ -103,14 +103,3 @@ func (err *HTTPError) Error() string {
|
||||
func (err *HTTPError) Unwrap() error {
|
||||
return err.Err
|
||||
}
|
||||
|
||||
// DAVError is a XML error with HTTP status and a human readable message
|
||||
type DAVError struct {
|
||||
Code int
|
||||
Msg string
|
||||
Err Error
|
||||
}
|
||||
|
||||
func (err *DAVError) Error() string {
|
||||
return err.Msg
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package internal
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"net/http"
|
||||
@@ -10,16 +11,19 @@ import (
|
||||
)
|
||||
|
||||
func ServeError(w http.ResponseWriter, err error) {
|
||||
if davErr, ok := err.(*DAVError); ok {
|
||||
w.WriteHeader(davErr.Code)
|
||||
ServeXML(w).Encode(davErr.Err)
|
||||
code := http.StatusInternalServerError
|
||||
var httpErr *HTTPError
|
||||
if errors.As(err, &httpErr) {
|
||||
code = httpErr.Code
|
||||
}
|
||||
|
||||
var errElt *Error
|
||||
if errors.As(err, &errElt) {
|
||||
w.WriteHeader(code)
|
||||
ServeXML(w).Encode(errElt)
|
||||
return
|
||||
}
|
||||
|
||||
code := http.StatusInternalServerError
|
||||
if httpErr, ok := err.(*HTTPError); ok {
|
||||
code = httpErr.Code
|
||||
}
|
||||
http.Error(w, err.Error(), code)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user