gowebdav icon indicating copy to clipboard operation
gowebdav copied to clipboard

feat: handle 404 on propfind

Open fmartingr opened this issue 3 years ago • 4 comments

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.

fmartingr avatar Jun 04 '22 06:06 fmartingr

why not use gowebdav.IsErrNotFound(err) ?

zhijian-pro avatar Jun 22 '22 15:06 zhijian-pro

why not use gowebdav.IsErrNotFound(err) ?

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

fmartingr avatar Jun 22 '22 18:06 fmartingr

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.

chripo avatar Oct 12 '22 17:10 chripo

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 :)

fmartingr avatar Oct 13 '22 08:10 fmartingr

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

chripo avatar Oct 13 '22 21:10 chripo

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!

chripo avatar Oct 20 '22 23:10 chripo