Skip to content

Commit 2b31535

Browse files
committed
refact: errors
1 parent 066bc9f commit 2b31535

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

Sources/VRCKit/APIClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public final class APIClient {
4747
func encodeAuthorization(_ username: String, _ password: String) throws -> String {
4848
let authString = "\(username):\(password)"
4949
guard let payload = authString.data(using: .utf8) else {
50-
throw VRCKitError.unexpectedError
50+
throw VRCKitError.unexpected
5151
}
5252
return "Basic \(payload.base64EncodedString())"
5353
}
@@ -97,7 +97,7 @@ public final class APIClient {
9797

9898
let (data, response) = try await URLSession.shared.data(for: request)
9999
guard let response = response as? HTTPURLResponse else {
100-
throw VRCKitError.invalidResponseError
100+
throw VRCKitError.invalidResponse
101101
}
102102
return (data, response)
103103
}

Sources/VRCKit/Errors.swift

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum VRCKitError: Error, LocalizedError {
1919
case clientDeallocated
2020

2121
/// Represents an error indicating an invalid response was received.
22-
case invalidResponseError
22+
case invalidResponse
2323

2424
/// Represents an error indicating an invalid request with additional details.
2525
case invalidRequest(_ details: String)
@@ -28,28 +28,21 @@ public enum VRCKitError: Error, LocalizedError {
2828
case unauthorized
2929

3030
/// Represents an unexpected error.
31-
case unexpectedError
31+
case unexpected
3232

3333
/// Represents an url error.
3434
case urlError
3535

3636
/// Provides a localized description of the error.
3737
public var errorDescription: String? {
3838
switch self {
39-
case .apiError:
40-
"API Error"
41-
case .clientDeallocated:
42-
"Client Deallocated"
43-
case .invalidResponseError:
44-
"Invalid Response Error"
45-
case .invalidRequest:
46-
"Invalid Request"
47-
case .unauthorized:
48-
"Unauthorized"
49-
case .unexpectedError:
50-
"Unexpected Error"
51-
case .urlError:
52-
"URL Error"
39+
case .apiError: "API Error"
40+
case .clientDeallocated: "Client Deallocated"
41+
case .invalidResponse: "Invalid Response"
42+
case .invalidRequest: "Invalid Request"
43+
case .unauthorized: "Unauthorized"
44+
case .unexpected: "Unexpected"
45+
case .urlError: "URL Error"
5346
}
5447
}
5548

Sources/VRCKit/Services/AuthenticationService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class AuthenticationService: APIService, AuthenticationServiceProtocol {
2929
} catch _ as DecodingError {
3030
let result: RequiresTwoFactorAuthResponse = try Serializer.shared.decode(response.data)
3131
guard let requires = result.requires else {
32-
throw VRCKitError.unexpectedError
32+
throw VRCKitError.unexpected
3333
}
3434
return requires
3535
}

0 commit comments

Comments
 (0)