Build iOS App / Build .ipa and publish source (push) Successful in 22s
When a PR's head branch is behind main (or conflicts), Gitea's merge returns
409. Previously the app just showed an error. Now: on a 409 the app calls
POST /pulls/{index}/update (merges base into head), then retries the merge
once. Add APIError.mergeConflict for a clear message and map 409 in the
client. Bump to 2.6.
39 lines
1.3 KiB
Swift
39 lines
1.3 KiB
Swift
import Foundation
|
|
|
|
enum APIError: LocalizedError, Equatable {
|
|
case invalidURL
|
|
case invalidResponse
|
|
case httpStatus(Int, String?)
|
|
case decoding(String)
|
|
case unauthorized
|
|
case notFound
|
|
case mergeConflict
|
|
|
|
var errorDescription: String? {
|
|
switch self {
|
|
case .invalidURL:
|
|
return "The instance URL is invalid."
|
|
case .invalidResponse:
|
|
return "The server returned an invalid response."
|
|
case .httpStatus(let code, let message):
|
|
if code == 401 || code == 403 {
|
|
return "Authentication failed. Check your token."
|
|
}
|
|
if code == 409 {
|
|
return "This branch is out of date or conflicts with the base branch. Update the branch and try again."
|
|
}
|
|
return message?.isEmpty == false
|
|
? "Server error (\(code)): \(message!)"
|
|
: "Server error (\(code))."
|
|
case .decoding(let detail):
|
|
return "Could not parse the server response: \(detail)"
|
|
case .unauthorized:
|
|
return "Authentication failed. Check your token."
|
|
case .notFound:
|
|
return "Not found."
|
|
case .mergeConflict:
|
|
return "This branch is out of date or conflicts with the base branch. Update the branch and try again."
|
|
}
|
|
}
|
|
}
|