emersion / go-webdav

A Go library for WebDAV, CalDAV and CardDAV
MIT License
317 stars 67 forks source link

Small error improvements #71

Closed emersion closed 2 years ago

emersion commented 2 years ago

cc @bitfehler

emersion commented 2 years ago

Hm, "internal: return a DAVError instead of an Error" is a bit strange because it wraps DAVError into HTTPError, duplicating the HTTP code. We might want to pick between two strategies:

bitfehler commented 2 years ago

Sorry, I never really looked much at the client code before, and it took me a moment to understand the error handling you added there :slightly_smiling_face:

I am not entirely sure which approach sounds better. On the one hand, since both are essentially different protocols, separating them seems reasonable. Yet, since they map so closely to each other, maybe not. I think in the client library, both would be easy to implement, but I have no idea how tedious proper handling would be in a client application.

On the server side, however, I'd be worried that separating them would result in a lot of noisy code, like "if it's a http error and code X or a dav error and code X, do this, same for code Y, etc." without adding much value. If the only difference is a human-readable error message, getting that from an optional wrapped error seems much easier. Hence I'd slightly lean toward your first suggestion. But it's not a strong opinion and I might very well be missing something.

emersion commented 2 years ago

Here's how the first approach would look like.

bitfehler commented 2 years ago

Looks good to me... :slightly_smiling_face:

emersion commented 2 years ago

Thanks for the feedback!