mirror of
https://codeberg.org/secana/Forji.git
synced 2026-06-16 05:13:55 -07:00
refactor: use ForgejoKit error categories
This commit is contained in:
parent
075669d87e
commit
1db69bfc77
1 changed files with 21 additions and 16 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue