// 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 titletype and details JSON properties.
// See https://readium.org/technical/readium-lsd-specification/#31-handling-errors
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 thehttpStatusCode
property (number) and httpResponseBody (string) // when the response body cannot be parsed to JSON. // Otherwise, it can be an object with thehttpStatusCode
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 providestitle
type
anddetails
JSON properties. // See https://readium.org/technical/readium-lsd-specification/#31-handling-errors