Skip to content

Commit 066bc9f

Browse files
committed
feat: define an unauthorized error in VRCKitError, apply to error handler
1 parent feb0aba commit 066bc9f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Sources/VRCKit/Errors.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public enum VRCKitError: Error, LocalizedError {
2424
/// Represents an error indicating an invalid request with additional details.
2525
case invalidRequest(_ details: String)
2626

27+
/// Represents an error indicating an authentication failure.
28+
case unauthorized
29+
2730
/// Represents an unexpected error.
2831
case unexpectedError
2932

@@ -41,6 +44,8 @@ public enum VRCKitError: Error, LocalizedError {
4144
"Invalid Response Error"
4245
case .invalidRequest:
4346
"Invalid Request"
47+
case .unauthorized:
48+
"Unauthorized"
4449
case .unexpectedError:
4550
"Unexpected Error"
4651
case .urlError:

Sources/VRCKit/Utils/Serializer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ final class Serializer {
3030
} catch let error as DecodingError {
3131
do {
3232
let errorResponse = try decoder.decode(ErrorResponse.self, from: data)
33-
throw VRCKitError.apiError(errorResponse.error.message)
33+
if errorResponse.error.statusCode == 401 {
34+
throw VRCKitError.unauthorized
35+
} else {
36+
throw VRCKitError.apiError(errorResponse.error.message)
37+
}
3438
} catch _ as DecodingError {
3539
// for debug
3640
print(type(of: T.self))

0 commit comments

Comments
 (0)