perry-mitchell / webdav-client

WebDAV client written in Typescript for NodeJS and the browser
MIT License
674 stars 146 forks source link

Handle upstream error #53

Closed zh99998 closed 7 years ago

zh99998 commented 7 years ago

when something wrong happens, like a server bug as https://github.com/fruux/sabre-dav/issues/988, may get a invalid response.

currently some method like getDirectoryContents will resolve a empty array. it's very dangerous since application will think it's working well and there is no file in such directory.

it should reject with error.

perry-mitchell commented 7 years ago

Hi @zh99998 - That doesn't look like it'd be returning a non-200 response code. If the code is 200 OK then this library will (and should imo) treat it as success.

Is there any way you could attach a copy of the response in its entirety (with headers)? Of course you could strip sensitive info.. but having that would make this much easier. CURL output would do. So long as it's not 200 OK..

zh99998 commented 7 years ago

no only get a valid xml reply then library should treat as success.

for example, fetch() or XMLHttpRequest, if requested a json, got a 200 HTML, it will reject.

perry-mitchell commented 7 years ago

no only get a valid xml reply then library should treat as success.

I agree of course. Right now if the XML is invalid the library should break (it'd error somewhere). To confirm this, please attach an example of what you mean in terms of broken output.

zh99998 commented 7 years ago

well well, maybe it could also be a valid url... but ... still something wrong. since this library can't parse it... maybe I should call this is not a valid WebDAV document?

<br />
<b>Warning</b>:  stream_get_contents() expects parameter 2 to be integer, string given in <b>/usr/src/app/vendor/sabre/http/lib/Message.php</b> on line <b>81</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /usr/src/app/vendor/sabre/http/lib/Message.php:81) in <b>/usr/src/app/vendor/sabre/http/lib/Sapi.php</b> on line <b>58</b><br />
<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
 <d:response>
  <d:href>/storage/ygopro/</d:href>
  <d:propstat>
   <d:prop>
    <d:resourcetype>
     <d:collection/>
    </d:resourcetype>
    <d:quota-used-bytes>9223372036854775807</d:quota-used-bytes>
    <d:quota-available-bytes>9223372036854775807</d:quota-available-bytes>
   </d:prop>
   <d:status>HTTP/1.1 200 OK</d:status>
  </d:propstat>
 </d:response>
 <d:response>
  <d:href>/storage/ygopro/deck/</d:href>
  <d:propstat>
   <d:prop>
    <d:resourcetype>
     <d:collection/>
    </d:resourcetype>
    <d:quota-used-bytes>9223372036854775807</d:quota-used-bytes>
    <d:quota-available-bytes>9223372036854775807</d:quota-available-bytes>
   </d:prop>
   <d:status>HTTP/1.1 200 OK</d:status>
  </d:propstat>
 </d:response>
 <d:response>
  <d:href>/storage/ygopro/replay/</d:href>
  <d:propstat>
   <d:prop>
    <d:resourcetype>
     <d:collection/>
    </d:resourcetype>
    <d:quota-used-bytes>9223372036854775807</d:quota-used-bytes>
    <d:quota-available-bytes>9223372036854775807</d:quota-available-bytes>
   </d:prop>
   <d:status>HTTP/1.1 200 OK</d:status>
  </d:propstat>
 </d:response>
 <d:response>
  <d:href>/storage/ygopro/single/</d:href>
  <d:propstat>
   <d:prop>
    <d:resourcetype>
     <d:collection/>
    </d:resourcetype>
    <d:quota-used-bytes>9223372036854775807</d:quota-used-bytes>
    <d:quota-available-bytes>9223372036854775807</d:quota-available-bytes>
   </d:prop>
   <d:status>HTTP/1.1 200 OK</d:status>
  </d:propstat>
 </d:response>
</d:multistatus>
perry-mitchell commented 7 years ago

since this library can't parse it...

What do you mean? I can't test it right now, but it looks valid - especially seeing as the result was 200 OK. This should resolve as per normal judging by the output.

The warnings at the top look like a problem with the server, not this library currently (I guess you've already figured that judging by your other issue you posted). Warnings are not failures so the 200 is not unexpected.

EDIT: I can feed this in to my testing setup at home to double check of course.

zh99998 commented 7 years ago

This should resolve as per normal judging by the output.

but it resolved a empty array.. if it treated as a normal, it should resolve ["/ygopro/deck/", "ygopro/single/", "/ygopro/single/"], but now it resolve []

perry-mitchell commented 7 years ago

What was the directory you requested the contents of?

zh99998 commented 7 years ago

I requested url /storage/ygopro

/storage/ is base href, directory is /ygopro

perry-mitchell commented 7 years ago

@zh99998 Are you still experiencing this issue? If you're not I'll probably close this. This was before the rewrite.

zh99998 commented 7 years ago

not tested, I can't reproduce this since server problem was fixed.

maybe this can be closed and if I meet problem again I'll open new issue.

2017-08-31 14:35 GMT+08:00 Perry Mitchell notifications@github.com:

@zh99998 https://github.com/zh99998 Are you still experiencing this issue? If you're not I'll probably close this. This was before the rewrite.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/perry-mitchell/webdav-client/issues/53#issuecomment-326203855, or mute the thread https://github.com/notifications/unsubscribe-auth/AAV8xn8lqXfyzKtKY3Aa3suxt49Sn1cwks5sdlRJgaJpZM4OjusS .