Errors
Every error a call can throw, and what to do about it.
Every client method throws DifferentRequestsError. The screens in the package already handle this and put the error next to the control that was tapped — you only need this when you are calling the client yourself.
do {
let answer = try await requests.client.request(id: "req_4f2a")
show(answer.request)
} catch let error as DifferentRequestsError {
if let seconds = error.retryAfterSeconds {
schedule(after: seconds)
} else {
switch error {
case .api(let refusal):
logger.error("DifferentRequests refused: \(refusal.message)")
case .networkError:
logger.error("DifferentRequests could not be reached")
default:
logger.error("DifferentRequests: \(error.localizedDescription)")
}
}
}What each one means
| Error | What happened, and what to do |
|---|---|
notAuthenticated | A write with nobody signed in. Thrown before anything is sent. Call createSession first. |
api(.unauthenticated) | The DRIdentityProof is missing, expired, or signed with a replaced signing secret. Fix it on your server and show the user nothing. |
api(.invalidArgument) | Something the user typed is invalid: too long, or empty. Show them what to change. |
api(.notFound) | The request, app or user doesn't exist, or belongs to another app. |
api(.planRequired) | This screen or feature isn't on the app's plan. Read the config and hide it instead. |
api(.rateLimited) | The rate limit is reached. Wait retryAfterSeconds, then retry. |
networkError | The device could not reach the server. Retry this one; retrying most other errors won't help. |
invalidBaseURL | A base URL that is not https. Thrown when you create the client, not on the first request. |
What not to show a user
A server's message is written for whoever reads a log, and may name internals. The package's own screens never show one to a user, and neither should yours. The code is what to branch on; the words are for you.
Thrown before anything is sent
notAuthenticated is thrown on the device when a write needs a signed-in user and there is none. Nothing is sent, so it fails at once.