diff --git a/Forji/Forji/Services/AuthenticationService.swift b/Forji/Forji/Services/AuthenticationService.swift index 05cbb70..d59a82c 100644 --- a/Forji/Forji/Services/AuthenticationService.swift +++ b/Forji/Forji/Services/AuthenticationService.swift @@ -257,18 +257,14 @@ enum SessionRestoreError: LocalizedError, Equatable { private static func fromAuthenticationError(_ error: AuthenticationError) -> SessionRestoreError { switch error { - case .invalidCredentials, .otpRequired: - .tokenExpired - case .serverNotFound: - .serverNotFound case .certificateError: .certificateError case .invalidResponse: .invalidServerResponse - case let .unknownError(statusCode): - fromHTTPStatusCode(statusCode) case .invalidURL: .serverNotFound + case .invalidCredentials, .otpRequired, .serverNotFound, .unknownError: + fromHTTPErrorCategory(error.httpErrorCategory, statusCode: error.httpStatusCode) } } @@ -278,8 +274,8 @@ enum SessionRestoreError: LocalizedError, Equatable { .serverNotFound case .invalidResponse, .decodingFailed: .invalidServerResponse - case let .httpError(statusCode, _): - fromHTTPStatusCode(statusCode) + case .httpError: + fromHTTPErrorCategory(error.httpErrorCategory, statusCode: error.httpStatusCode) case .noActiveInstance: .tokenValidationFailed case .notMergeable, .mergeConflict: @@ -287,18 +283,27 @@ enum SessionRestoreError: LocalizedError, Equatable { } } - private static func fromHTTPStatusCode(_ statusCode: Int) -> SessionRestoreError { - switch statusCode { - case 401: + private static func fromHTTPErrorCategory( + _ category: HTTPErrorCategory?, + statusCode: Int?, + ) -> SessionRestoreError { + switch category { + case .authentication: .tokenExpired - case 403: + case .permissionDenied: .tokenPermissionDenied - case 404: + case .notFound: .serverNotFound - case 500 ... 599: + case .server: .serverUnavailable - default: - .tokenValidationFailedHTTPStatus(statusCode) + case .other: + if let statusCode { + .tokenValidationFailedHTTPStatus(statusCode) + } else { + .tokenValidationFailed + } + case nil: + .tokenValidationFailed } } }