-
Notifications
You must be signed in to change notification settings - Fork 146
Description
OpenAPIRuntime makes it impossible to access precise error localized message and codes.
To reproduce:
- Generate some code from an OpenAPI specification, as documented.
- Setup a
Client
with aURLSessionTransport
- Run the client and make sure an error is reported by turning on the Airplane mode on a device.
Expected: It is possible to grab the original cause of the error, and the original localized message of the underlying URLError. Very precisely, I expect to be able to detect the notConnectedToInternet
code of URLError
, and confidently display the excellent French message "La connexion Internet semble interrompue." that is embedded in the NSLocalizedDescription
key of the URLError. This is very important for a quality user interface. Experience shows that URLError
messages are very suitable for display (at least for some specific codes).
// Expected
let clientError: ClientError
if let urlError = clientError.underlyingError as? URLError {
// 😊 Deal with the raw URLError, without any information loss
}
What happens instead: I get a ClientError
whose underlyingError
is a RuntimeError
(internal to OpenAPIRuntime) that hides the original error in its transportFailed
case, and corrupts the localized message in its prettyDescription
by prepending English text.
// 😭 I can't possible present any suitable error message to the end user?
// I have no error code, and no localized message.
//
// Prints:
// Optional("Client error - operationID: ..., underlying error: Transport failed with error: La connexion Internet semble interrompue.")
// RuntimeError
// nil
print(clientError.errorDescription)
print(type(of: clientError.underlyingError))
print((clientError.underlyingError as? LocalizedError)?.errorDescription)
In summary, please don't hide the raw errors. I opted in for URLSession
by providing URLSessionTransport
: I expect to be able to get some genuine URLError
at some point, along with their high quality information and localized messages, without any information loss.