File tree Expand file tree Collapse file tree 4 files changed +41
-7
lines changed Expand file tree Collapse file tree 4 files changed +41
-7
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,14 @@ struct APIClient: Sendable {
33
33
/// There are some GoTrue endpoints that can return a `PostgrestError`, for example the
34
34
/// ``AuthAdmin/deleteUser(id:shouldSoftDelete:)`` that could return an error in case the
35
35
/// user is referenced by other schemas.
36
- let postgrestError = try configuration. decoder. decode (
36
+ if let postgrestError = try ? configuration. decoder. decode (
37
37
PostgrestError . self,
38
38
from: response. data
39
- )
40
- throw postgrestError
39
+ ) {
40
+ throw postgrestError
41
+ }
42
+
43
+ throw HTTPError ( data: response. data, response: response. response)
41
44
}
42
45
43
46
return response
Original file line number Diff line number Diff line change @@ -110,8 +110,11 @@ public class PostgrestBuilder: @unchecked Sendable {
110
110
let response = try await http. fetch ( request, baseURL: configuration. url)
111
111
112
112
guard 200 ..< 300 ~= response. statusCode else {
113
- let error = try configuration. decoder. decode ( PostgrestError . self, from: response. data)
114
- throw error
113
+ if let error = try ? configuration. decoder. decode ( PostgrestError . self, from: response. data) {
114
+ throw error
115
+ }
116
+
117
+ throw HTTPError ( data: response. data, response: response. response)
115
118
}
116
119
117
120
let value = try decode ( response. data)
Original file line number Diff line number Diff line change @@ -33,8 +33,11 @@ public class StorageApi: @unchecked Sendable {
33
33
34
34
let response = try await http. rawFetch ( request)
35
35
guard ( 200 ..< 300 ) . contains ( response. statusCode) else {
36
- let error = try configuration. decoder. decode ( StorageError . self, from: response. data)
37
- throw error
36
+ if let error = try ? configuration. decoder. decode ( StorageError . self, from: response. data) {
37
+ throw error
38
+ }
39
+
40
+ throw HTTPError ( data: response. data, response: response. response)
38
41
}
39
42
40
43
return response
Original file line number Diff line number Diff line change
1
+ //
2
+ // HTTPError.swift
3
+ //
4
+ //
5
+ // Created by Guilherme Souza on 07/05/24.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ #if canImport(FoundationNetworking)
11
+ import FoundationNetworking
12
+ #endif
13
+
14
+ /// A generic error from a HTTP request.
15
+ ///
16
+ /// Contains both the `Data` and `HTTPURLResponse` which you can use to extract more information about it.
17
+ public struct HTTPError : Error , Sendable {
18
+ public let data : Data
19
+ public let response : HTTPURLResponse
20
+
21
+ public init ( data: Data , response: HTTPURLResponse ) {
22
+ self . data = data
23
+ self . response = response
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments