Different Requests

Errors

Every refusal a call can come back with, and what to do about it.

Every client method throws DifferentRequestsError. The screens in the package already handle this and put the refusal 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

RefusalWhat happened, and what to do
notAuthenticatedA write with nobody signed in. Thrown before anything is sent. Call createSession first.
api(.invalidArgument)Something the person typed was refused — too long, or empty. Show them what to change.
api(.notFound)That request, app or person is not there, or is not yours.
api(.planRequired)This surface is not on the app's plan. Read the config and hide it instead.
api(.rateLimited)The allowance is spent. retryAfterSeconds says how long to wait.
networkErrorThe phone could not reach us. Worth a retry; most of the others are not.
invalidBaseURLA base URL that is not https. Refused where it was written, not on the first call.

What not to show a person

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 person, and neither should yours. The code is what to branch on; the words are for you.

Refused before it is sent

notAuthenticated is thrown locally, from what the contract says a call needs. A write with no session is refused on the phone rather than costing a round trip to be told no.