Skip to content

Commit

Permalink
feat: improve HTTP Error (#372)
Browse files Browse the repository at this point in the history
- Export error so clients can catch it
- Add localized description for better print statements
  • Loading branch information
leoMehlig authored May 9, 2024
1 parent e5c564a commit ea25236
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/PostgREST/PostgrestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ConcurrencyExtras
import Foundation

public typealias PostgrestError = _Helpers.PostgrestError
public typealias HTTPError = _Helpers.HTTPError
public typealias AnyJSON = _Helpers.AnyJSON

#if canImport(FoundationNetworking)
Expand Down
10 changes: 10 additions & 0 deletions Sources/_Helpers/SharedModels/HTTPError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ public struct HTTPError: Error, Sendable {
self.response = response
}
}

extension HTTPError: LocalizedError {
public var errorDescription: String? {
var message = "Status Code: \(self.response.statusCode)"
if let body = String(data: data, encoding: .utf8) {
message += " Body: \(body)"
}
return message
}
}

0 comments on commit ea25236

Please sign in to comment.