Skip to content

Commit 9458952

Browse files
committed
Update ResponseError.swift
1 parent d9ce1ae commit 9458952

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/replicate-kit-swift/error/ResponseError.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,25 @@ public struct ResponseError: Hashable, CustomStringConvertible, LocalizedError,
5454
/// - response: URLResponse
5555
/// - data: Received data
5656
/// - Returns: Error with a description why server cannot or will not process the request if it managed to parse data response, standard status error or nil if request was successful
57-
internal let errorFn : Http.Validate.Status.ErrorFn = { status, response, data -> Error? in
57+
internal let errorFn : Http.Validate.Status.ErrorFn = {
58+
status, response, data -> Error? in
59+
60+
/// Default error response if not valid status code and we can't decode error format response
61+
let error = Http.Errors.status(status, response, data)
5862

5963
if (200...299).contains(status) { return nil }
6064

6165
guard (400...499).contains(status) else{
62-
return Http.Errors.status(status, response, data)
66+
return error
6367
}
6468

6569
guard let data = data else{
66-
return Http.Errors.status(status, response, data)
70+
return error
6771
}
6872

6973
if let error = try? JSONDecoder().decode(ResponseError.self, from: data){
7074
return error
7175
}
7276

73-
return Http.Errors.status(status, response, data)
77+
return error
7478
}

0 commit comments

Comments
 (0)