Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the status code on failure #7

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Sources/SwiftGraphQL/HTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ private func send<Type, TypeLock>(
return completionHandler(.failure(.network(error)))
}

guard let httpResponse = response as? HTTPURLResponse,
(200 ... 299).contains(httpResponse.statusCode)
else {
return completionHandler(.failure(.badstatus))
guard let httpResponse = response as? HTTPURLResponse else {
return completionHandler(.failure(.badstatus(nil)))
}
guard (200 ... 299).contains(httpResponse.statusCode) else {
return completionHandler(.failure(.badstatus(httpResponse.statusCode)))
}

// Try to serialize the response.
Expand Down Expand Up @@ -144,7 +145,7 @@ public enum HttpError: Error {
case timeout
case network(Error)
case badpayload
case badstatus
case badstatus(Int?)
case cancelled
case decodingError(Error, extensions: [String: AnyCodable]?)
case graphQLErrors([GraphQLError], extensions: [String: AnyCodable]?)
Expand All @@ -154,10 +155,10 @@ extension HttpError: Equatable {
public static func == (lhs: SwiftGraphQL.HttpError, rhs: SwiftGraphQL.HttpError) -> Bool {
// Equals if they are of the same type, different otherwise.
switch (lhs, rhs) {
case (.badstatus(let a), .badstatus(let b)): return a == b
case (.badURL, badURL),
(.timeout, .timeout),
(.badpayload, .badpayload),
(.badstatus, .badstatus),
(.cancelled, .cancelled),
(.network, .network),
(.decodingError, .decodingError),
Expand Down