studio-b12 / gowebdav

A golang WebDAV client library and command line tool.
BSD 3-Clause "New" or "Revised" License
309 stars 89 forks source link

Improve Error Handling #54

Closed zekroTJA closed 2 years ago

zekroTJA commented 2 years ago

I found some time to try to tackle the error handling issue described in #28.

Therefore, all request methods which only returned status code do now return proper error values as well. Also, path errors now contain an instance of StatusError which contains the erroneous status code. This makes handling specific errors more trivial.

As well, I put all error related functions and structures into errors.go to give a better overview over the codebase.

While testing, I also noticed that Client#req fails when a file stream is passed as body and the request is repeatet due to an authentication error. I found out that - for whatever reason - http.Client#Do closes the passed io.Closer stream.

Here is a quick demonstration of this behavior: https://go.dev/play/p/OouD3-GAD0M

This causes Seek on the stream to fail after the first request because the file is closed. To inhibit the closing, I wrapped the stream in a struct implementation which overrides Close so that it can't be closed by the Do method.

Even though I've tested through all methods using the client, I am not completely sure if my changes introduce any unwanted side effect, wo it would be nice if you could take a look over it. 😅

chripo commented 2 years ago

Thanks for your improvements. The error handling is well done.

Maybe we should handle 2889239 in a separate pr?

zekroTJA commented 2 years ago

Thanks for your improvements. The error handling is well done.

Maybe we should handle 2889239 in a separate pr?

Yep, I actually didn't thought through when the body should be closed otherwise, but I have an idea how to handle this. I've picket the commit into dev-bodyclosing for further modification and reverted it in this branch therefore.