Error handling
Every SDK operation reports failures as a SignicatOIDCError. The async methods throw this error. The OIDCConfiguration initialiser throws the same type when a value is invalid.
Error reference
The SignicatOIDCError includes a stable error code, in addition to any protocol details that the Signicat service returned.
You should decide how your app responds to errors based on code rather than on the error message text. Error codes are part of the SDK contract, whereas messages are not. OAuth descriptions can also change.
Use error messages and OAuth descriptions to diagnose problems. Show end-users a message based on the error code.
For an overview of the error properties, see the table below:
do {
let session = try await SignicatOIDCClient.shared.login()
showLoggedInScreen(session)
} catch let error as SignicatOIDCError {
switch error.code {
case .authorizationCancelled:
showLoginScreen()
case .authorizationInProgress:
return // Another login or logout is running.
default:
showGenericError()
}
} catch {
showGenericError()
}
Error codes
For an overview of possible error codes, see the table below:
Log error detail
The toJson() method serialises error details into a compact JSON string, without the properties that are nil.
You can use this for diagnostics and support tickets.
import OSLog
import SignicatOIDC
let logger = Logger(subsystem: "com.example.app", category: "Login")
@MainActor
func logOut() async {
do {
try await SignicatOIDCClient.shared.logout()
} catch let error as SignicatOIDCError {
logger.error("Logout failed: \(error.toJson(), privacy: .public)")
} catch {
logger.error("Logout failed: \(error.localizedDescription)")
}
}
If the end-session endpoint returns HTTP 500, the example logs the following details, shown here with line breaks:
{
"code": "logoutFailed",
"message": "OIDC logout failed.",
"underlyingErrorDescription": "Logout endpoint returned HTTP 500"
}
Support
If you need help or want to report an issue, contact us by creating a support ticket in the Signicat Dashboard.
When creating a support ticket, you should include the serialised error details from the toJson() method.