Skip to content

Commit

Permalink
fix: unauthorized error
Browse files Browse the repository at this point in the history
  • Loading branch information
makinosp committed Nov 2, 2024
1 parent f383f65 commit 7c88c46
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Sources/VRCKit/Utils/Serializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ final class Serializer: Sendable {

/// Decodes JSON data into a specified `Decodable` type.
/// - Parameter data: The JSON data to decode.
/// - Throws: `VRCKitError.apiError` if the decoded data contains an API error.
/// - Throws: `DecodingError` if the decoding process fails.
/// - Throws:
/// - `VRCKitError.unauthorized` if the decoded data contains an unauthentized error.
/// - `VRCKitError.apiError` if the decoded data contains an API error.
/// - `DecodingError` if the decoding process fails.
/// - Returns: The decoded object of type `T`.
func decode<T>(_ data: Data) throws -> T where T: Decodable {
do {
Expand All @@ -35,15 +37,11 @@ final class Serializer: Sendable {
do {
let errorResponse = try decoder.decode(ErrorResponse.self, from: data)
if errorResponse.error.statusCode == 401 {
throw VRCKitError.credentialNotSet
throw VRCKitError.unauthorized
} else {
throw VRCKitError.apiError(errorResponse.error.message)
}
} catch _ as DecodingError {
// for debug
print(type(of: T.self))
print(error)
print(String(data: data, encoding: .utf8) ?? "")
throw error
}
}
Expand Down

0 comments on commit 7c88c46

Please sign in to comment.