Closed bitfehler closed 2 years ago
Of course this would not just be for backends. I think it would help take care of all these TODOs: https://github.com/emersion/go-webdav/blob/master/carddav/server.go#L406-L421
I like the idea of using a special error type for this. Although maybe it'd be better to have a new internal.DAVError
type, and special-case it in internal.ServeError
to do the proper XML marshalling and Content-Type etc.
Totally agree, did this now. Also moved some stuff around, let me know if you'd like to see something elsewhere. I also update the commit message with some details. In general I think this will be a useful mechanism. Of course something might show up down the road that might require some modification, but I guess that's life...
I think I addressed all your comments
Backends will need some way to signal that a precondition error occurred (and specifying which one) without causing the server to return a 500. This commit adds an exported function to create a specific error for this. The existing error handling routine is slightly adapted to handle this error in such a way that it (almost) returns the desired result.
Usage would be something like:
As is, this approach is missing a few things to be correct:
<?xml ...
)I'd like to get your opinion as early as possible before I start writing more code.
Other approaches I could think of would be creating another, more specific error type for this, using the context for communicating specifics, or adding a third return value to the relevant interface funcions.
What I think is nice about this approach is that it leaves the interfaces as is and does not require handling of this kind of errors in all the places they could occur.
What do you think?