[AltServer] Moves core ConnectionManager logic to AltKit

Refactors ConnectionManager to use arbitrary RequestHandlers and ConnectionHandlers. This allows the core AltServer request logic to be shared across different targets with different connection types.
This commit is contained in:
Riley Testut
2020-06-04 19:06:13 -07:00
parent 0b36214bb5
commit 70f897699c
23 changed files with 959 additions and 785 deletions

View File

@@ -0,0 +1,36 @@
//
// ALTServerError+Conveniences.swift
// AltKit
//
// Created by Riley Testut on 6/4/20.
// Copyright © 2020 Riley Testut. All rights reserved.
//
import Foundation
public extension ALTServerError
{
init<E: Error>(_ error: E)
{
switch error
{
case let error as ALTServerError: self = error
case is DecodingError: self = ALTServerError(.invalidRequest, underlyingError: error)
case is EncodingError: self = ALTServerError(.invalidResponse, underlyingError: error)
case let error as NSError:
var userInfo = error.userInfo
if !userInfo.keys.contains(NSUnderlyingErrorKey)
{
// Assign underlying error (if there isn't already one).
userInfo[NSUnderlyingErrorKey] = error
}
self = ALTServerError(.unknown, userInfo: error.userInfo)
}
}
init<E: Error>(_ code: ALTServerError.Code, underlyingError: E)
{
self = ALTServerError(.invalidRequest, userInfo: [NSUnderlyingErrorKey: underlyingError])
}
}