2020-06-04 19:06:13 -07:00
|
|
|
//
|
|
|
|
|
// ALTServerError+Conveniences.swift
|
|
|
|
|
// AltKit
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 6/4/20.
|
|
|
|
|
// Copyright © 2020 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2021-09-13 15:27:40 -07:00
|
|
|
import AltSign
|
2020-06-04 19:06:13 -07:00
|
|
|
|
|
|
|
|
public extension ALTServerError
|
|
|
|
|
{
|
|
|
|
|
init<E: Error>(_ error: E)
|
|
|
|
|
{
|
|
|
|
|
switch error
|
|
|
|
|
{
|
|
|
|
|
case let error as ALTServerError: self = error
|
2021-05-20 11:46:38 -07:00
|
|
|
case let error as ALTServerConnectionError: self = ALTServerError(.connectionFailed, underlyingError: error)
|
2021-09-13 15:27:40 -07:00
|
|
|
case let error as ALTAppleAPIError where error.code == .invalidAnisetteData: self = ALTServerError(.invalidAnisetteData, underlyingError: error)
|
2020-06-04 19:06:13 -07:00
|
|
|
case is DecodingError: self = ALTServerError(.invalidRequest, underlyingError: error)
|
|
|
|
|
case is EncodingError: self = ALTServerError(.invalidResponse, underlyingError: error)
|
|
|
|
|
case let error as NSError:
|
2023-01-24 13:56:41 -06:00
|
|
|
// Assign error as underlying error, even if there already is one,
|
|
|
|
|
// because it'll still be accessible via error.underlyingError.underlyingError.
|
2020-06-04 19:06:13 -07:00
|
|
|
var userInfo = error.userInfo
|
2024-08-06 10:43:52 +09:00
|
|
|
userInfo[NSUnderlyingErrorKey] = error
|
2020-06-05 14:19:40 -07:00
|
|
|
self = ALTServerError(.underlyingError, userInfo: userInfo)
|
2020-06-04 19:06:13 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init<E: Error>(_ code: ALTServerError.Code, underlyingError: E)
|
|
|
|
|
{
|
2020-06-05 14:19:40 -07:00
|
|
|
self = ALTServerError(code, userInfo: [NSUnderlyingErrorKey: underlyingError])
|
2020-06-04 19:06:13 -07:00
|
|
|
}
|
|
|
|
|
}
|