Skip to content

Commit

Permalink
Add a reason to HTTPError for debuggability
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed Oct 27, 2023
1 parent 776e024 commit 6871243
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/Auth0Kit/AsyncHTTPClient+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import Foundation

struct HTTPError: Error {
let code: HTTPResponseStatus
let reason: String
}

extension HTTPClientResponse {
func assertSuccessful() async throws {
guard status.code >= 200 && status.code < 300 else {
throw HTTPError(code: status)
var body = try await body.collect(upTo: 1024)
let reason = body.readString(length: body.readableBytes) ?? ""
throw HTTPError(code: status, reason: reason)
}
}

Expand Down

0 comments on commit 6871243

Please sign in to comment.