Description
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:
- Manually corrupt a DRM key or other asset that will prevent the decryption of any EPUB resource.
- Put a breakpoint in the failure case of the GCDHTTPServer::handle(request:) function.
- Attempt to open the EPUB.
- Observe how
EPUBSpreadView
is presented but the error received from theGCDHTTPServer::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 aonFailure: (_ href: String, _ error: ResourceError) -> Void
parameter to all theserve...()
variants in the HTTPServer protocol.