Skip to content

Errors while loading a Resource in GCDHTTPServer are not bubbled up #398

Closed
@ettore

Description

@ettore

Describe the bug

If GCDWebServer fails to load a resource, the GCDHTTPServer adapter correctly catches the error and responds with a GCDWebServerErrorResponse (Bad Request 400). However in doing so it loses the contextual information of the error object, because the latter is not part of the response. This can be observed clearly in the implementation of the GCDHTTPServer::handle(request:) function, where the only thing that is transmitted up is the HTTP status code of the error. The error object would be useful to the app that uses Readium to display an informative error message to the user.

How to reproduce?

The following is just an example easily reproducible by using a DRM system conforming to the ContentProtection protocol:

  1. Manually corrupt a DRM key or other asset that will prevent the decryption of any EPUB resource.
  2. Put a breakpoint in the failure case of the GCDHTTPServer::handle(request:) function.
  3. Attempt to open the EPUB.
  4. Observe how EPUBSpreadView is presented but the error received from the GCDHTTPServer::handlers is lost.

Readium version

2.6.1

OS version

iOS 17

Testing device

iPhone 11 and various simulators

Environment

macOS: 13.5
platform: arm64
carthage: 0.39.1
Build version 15A507

Additional context

This was initially discussed in the Readium Slack, with the following suggestion:

  • expand the NavigatorDelegate API with something like NavigatorDelegate.navigator(_: Navigator, didFailToLoadResourceAt href: String, withError error: ResourceError);
  • forward the error from GCDHTTPServer to the navigator delegate, for example by adding a onFailure: (_ href: String, _ error: ResourceError) -> Void parameter to all the serve...() variants in the HTTPServer protocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions