Files
amiibo-service/Sources/AmiiboService/Public/Errors/AmiiboServiceError.swift
T

58 lines
2.1 KiB
Swift
Raw Normal View History

2025-10-07 22:32:54 +00:00
// ===----------------------------------------------------------------------===
2026-03-27 17:14:26 +00:00
//
2025-10-07 22:32:54 +00:00
// This source file is part of the Amiibo Service open source project
2026-03-27 17:14:26 +00:00
//
2026-03-22 23:39:48 +00:00
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
2025-10-07 22:32:54 +00:00
// Licensed under Apache license v2.0
2026-03-27 17:14:26 +00:00
//
// See LICENSE for license information
2025-10-07 22:32:54 +00:00
// See CONTRIBUTORS for the list of Amiibo Service project authors
//
2025-10-07 22:32:54 +00:00
// SPDX-License-Identifier: Apache-2.0
2026-03-27 17:14:26 +00:00
//
2025-10-07 22:32:54 +00:00
// ===----------------------------------------------------------------------===
2026-03-27 17:14:26 +00:00
import Foundation
2025-09-09 17:30:19 +00:00
/// A representation of all the possible errors that the ``AmiiboService`` service could throw.
public enum AmiiboServiceError: Error {
2026-03-22 23:39:48 +00:00
/// The request was malformed or contained invalid filter parameters.
case badRequest
2026-03-22 23:39:48 +00:00
/// The request was cancelled before a response was received.
2025-10-02 01:51:16 +00:00
case cancelled
2026-03-22 23:39:48 +00:00
/// The response body could not be decoded into the expected model.
case decoding
2026-03-22 23:39:48 +00:00
/// The backend service is currently unreachable due to a network or server issue.
case notAvailable
2026-03-22 23:39:48 +00:00
/// No results were found matching the given filter criteria.
case notFound
2026-03-22 23:39:48 +00:00
/// The server returned an undocumented HTTP status code.
case undocumented(_ statusCode: Int)
2026-03-22 23:39:48 +00:00
/// An unexpected error that does not fall into any other category.
case unknown
}
// MARK: - Equatable
extension AmiiboServiceError: Equatable {}
2026-03-27 17:14:26 +00:00
// MARK: - LocalizedError
extension AmiiboServiceError: LocalizedError {
// MARK: Properties
public var errorDescription: String? {
switch self {
case .badRequest: "The request was malformed or contained invalid filter parameters."
case .cancelled: "The request was cancelled before a response was received."
case .decoding: "The response body could not be decoded into the expected model."
case .notAvailable: "The backend service is currently unreachable due to a network or server issue."
case .notFound: "No results were found matching the given filter criteria."
case .undocumented(let statusCode): "The server returned an undocumented HTTP status code: \(statusCode)."
case .unknown: "An unexpected error occurred."
}
}
}