Skip to content

Commit ea25236

Browse files
authored
feat: improve HTTP Error (#372)
- Export error so clients can catch it - Add localized description for better print statements
1 parent e5c564a commit ea25236

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Sources/PostgREST/PostgrestClient.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ConcurrencyExtras
33
import Foundation
44

55
public typealias PostgrestError = _Helpers.PostgrestError
6+
public typealias HTTPError = _Helpers.HTTPError
67
public typealias AnyJSON = _Helpers.AnyJSON
78

89
#if canImport(FoundationNetworking)

Sources/_Helpers/SharedModels/HTTPError.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ public struct HTTPError: Error, Sendable {
2323
self.response = response
2424
}
2525
}
26+
27+
extension HTTPError: LocalizedError {
28+
public var errorDescription: String? {
29+
var message = "Status Code: \(self.response.statusCode)"
30+
if let body = String(data: data, encoding: .utf8) {
31+
message += " Body: \(body)"
32+
}
33+
return message
34+
}
35+
}

0 commit comments

Comments
 (0)