Vernissage/MastodonKit/Sources/MastodonKit/Errors/NetworkError.swift

22 lines
719 B
Swift
Raw Normal View History

2023-01-08 17:56:07 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import Foundation
2023-01-10 08:04:25 +01:00
public enum NetworkError: Error {
2023-01-08 17:56:07 +01:00
case notSuccessResponse(URLResponse)
}
extension NetworkError: LocalizedError {
public var errorDescription: String? {
switch self {
case .notSuccessResponse(let response):
2023-01-15 12:41:55 +01:00
let statusCode = response.statusCode()
2023-01-22 15:56:35 +01:00
return NSLocalizedString("Network request returned not success status code: '\(statusCode?.localizedDescription ?? "unknown")'. Request URL: '\(response.url?.string ?? "unknown")'.", comment: "It's error returned from remote server.")
2023-01-08 17:56:07 +01:00
}
}
}