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

feat: handle 404 on propfind #57

Closed fmartingr closed 2 years ago

fmartingr commented 2 years ago

Client.Stat was not returning a proper Go err for not found files, the ideal way to check this is using errors.Is(err, fs.ErrNotExist) but the client was returning a generic error.

I've updated the propfind to take 404 errors into account, retuning the above error making easier to evaluate that kind of situations.

zhijian-pro commented 2 years ago

why not use gowebdav.IsErrNotFound(err) ?

fmartingr commented 2 years ago

why not use gowebdav.IsErrNotFound(err) ?

That didn't work for me when I used gowebdav.Stat over files that 404'd.

chripo commented 2 years ago

Thank you for your pull request. I see this as a path towards a more consistent API. gowebdav.IsErrNotFound(err) doesn't work, because the status code may not be available at this time. In this particular case it is enough to add this 404 error handling into requests.go but with return newPathError("PROPFIND", path, rs.StatusCode) instead of return newNotExistError() to get IsErrorNotFound(err) working.

fmartingr commented 2 years ago

Thank you for your pull request. I see this as a path towards a more consistent API. gowebdav.IsErrNotFound(err) doesn't work, because the status code may not be available at this time. In this particular case it is enough to add this 404 error handling into requests.go but with return newPathError("PROPFIND", path, rs.StatusCode) instead of return newNotExistError() to get IsErrorNotFound(err) working.

Done!

I kept thinking that maybe using newPathError("PROPFIND", path, rs.StatusCode) for any rs.StatusCode > 400 maybe be more future proof, even if we don't have handlers for those errors yet. But I will leave that to you that know the project much better :)

chripo commented 2 years ago

Thank You!!! You have massively improved the project.

chripo commented 2 years ago

this was not that issue. it may be an other one, we need to find them. please run the tests and file suspicious result. if you writing an own client, consider the reference implementation cmd/gowebdav. thank you!