refactor: use ForgejoKit error categories (#31)

Problem
- SessionRestoreError now duplicates HTTP status-code classification that ForgejoKit exposes in 0.6.0.

Change
- Uses ForgejoKit's httpErrorCategory/httpStatusCode for auth and service restore failures.
- Keeps the same user-facing SessionRestoreError outcomes.
- Leaves network and certificate handling unchanged.

Tests
- DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild -quiet -project Forji/Forji.xcodeproj -scheme Forji -destination "platform=iOS Simulator,name=iPhone 17 Pro,OS=26.4.1" build-for-testing -only-testing:ForjiTests/SessionRestoreErrorTests
- DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild -quiet -project Forji/Forji.xcodeproj -scheme Forji -destination "platform=iOS Simulator,name=iPhone 17 Pro,OS=26.4.1" test-without-building -only-testing:ForjiTests/SessionRestoreErrorTests

Co-authored-by: Piotr Durlej <pdurlej@users.noreply.github.com>
Reviewed-on: https://codeberg.org/secana/Forji/pulls/31
This commit is contained in:
pdurlej 2026-05-17 21:29:12 +02:00 committed by secana
parent 075669d87e
commit a93130ee09

View file

@ -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
}
}
}