edrlab / thorium-reader

A cross platform desktop reading app, based on the Readium Desktop toolkit
https://www.edrlab.org/software/thorium-reader/
BSD 3-Clause "New" or "Revised" License
1.85k stars 157 forks source link

LSD renew and return should capture potential server errors #326

Closed danielweck closed 5 years ago

danielweck commented 5 years ago

https://github.com/readium/readium-desktop/blob/42a6ab3efa20879db9f8f4b6503e15551b93df19/src/main/services/lcp.ts#L187

https://github.com/readium/readium-desktop/blob/42a6ab3efa20879db9f8f4b6503e15551b93df19/src/main/services/lcp.ts#L214

=> use try/catch to capture a rejected promise.

See the LCP/LSD API usage documentation (scroll to the very bottom): https://github.com/readium/r2-navigator-js/blob/develop/README.md#lcp

Copy:

// Both LSD "renew" and "return" interactions can return errors (i.e. Promise.reject => try/catch with async/await) // when the server responds with HTTP statusCode < 200 || >= 300. // The err object in the above code snippet can be a number (HTTP status code) when no response body is available. // Otherwise, it can be an object with the httpStatusCode property (number) and httpResponseBody (string) // when the response body cannot be parsed to JSON. // Otherwise, it can be an object with the httpStatusCode property (number) and other arbitrary JSON properties, // depending on the server response. Typically, compliant LCP/LSD servers are expected to return Problem Details JSON (RFC7807), // which provides title type and details JSON properties. // See https://readium.org/technical/readium-lsd-specification/#31-handling-errors

danielweck commented 5 years ago

Same with register: https://github.com/readium/readium-desktop/blob/42a6ab3efa20879db9f8f4b6503e15551b93df19/src/main/services/lcp.ts#L161

danielweck commented 5 years ago

Related issue: https://github.com/readium/readium-desktop/issues/540

danielweck commented 5 years ago

Was duplicated: https://github.com/readium/readium-desktop/issues/540