<commit_before>// ----------------------------------------------------------------------------
//
//  HTTPRequestExecutorError.swift
//
//  @author <NAME> <<EMAIL>>
//
// ----------------------------------------------------------------------------

public struct HTTPRequestExecutorError: RequestExecutorError
{
// MARK: - Construction

    public init(error: HTTPClientError, request: HTTPRequest, response: HTTPResponse?) {
        self.init(reason: .httpClientError(error: error), request: request, response: response)
    }

    public init(error: HTTPRequestError, request: HTTPRequest, response: HTTPResponse?) {
        self.init(reason: .httpRequestError(error: error), request: request, response: response)
    }

    public init(error: HTTPResponseError, request: HTTPRequest, response: HTTPResponse?) {
        self.init(reason: .httpResponseError(error: error), request: request, response: response)
    }

    init(reason: Reason, request: HTTPRequest, response: HTTPResponse?)
    {
        self.reason = reason
        self.request = request
        self.response = response
    }

// MARK: - Properties

    public let reason: Reason

    public let request: HTTPRequest

    public let response: HTTPResponse?

// MARK: - Inner Types

    public enum Reason
    {
        case httpClientError(error: HTTPClientError)
        case httpRequestError(error: HTTPRequestError)
        case httpResponseError(error: HTTPResponseError)
    }

}

// ----------------------------------------------------------------------------

open class NestedError<T>: Error
{
// MARK: - Construction

    public init(cause: T?) {
        self.cause = cause
    }

// MARK: - Properties

    public let cause: T?

}

// ----------------------------------------------------------------------------

public protocol HTTPClientError: Error { }

// ----------------------------------------------------------------------------

public protocol HTTPRequestError: Error { }

open class HTTPRequestSerializationError: NestedError<Error>, HTTPRequestError { }

// ----------------------------------------------------------------------------

public protocol HTTPResponseError: Error { }

open class HTTPResponseSerializationError: NestedError<Error>, HTTPResponseError { }
open class HTTPResponseStatusCodeError: NestedError<Error>, HTTPResponseError { }

// ----------------------------------------------------------------------------<commit_msg>Implement CustomStringConvertible for NestedError<commit_after>// ----------------------------------------------------------------------------
//
//  HTTPRequestExecutorError.swift
//
//  @author <NAME> <<EMAIL>>
//
// ----------------------------------------------------------------------------

public struct HTTPRequestExecutorError: RequestExecutorError
{
// MARK: - Construction

    public init(error: HTTPClientError, request: HTTPRequest, response: HTTPResponse?) {
        self.init(reason: .httpClientError(error: error), request: request, response: response)
    }

    public init(error: HTTPRequestError, request: HTTPRequest, response: HTTPResponse?) {
        self.init(reason: .httpRequestError(error: error), request: request, response: response)
    }

    public init(error: HTTPResponseError, request: HTTPRequest, response: HTTPResponse?) {
        self.init(reason: .httpResponseError(error: error), request: request, response: response)
    }

    init(reason: Reason, request: HTTPRequest, response: HTTPResponse?)
    {
        self.reason = reason
        self.request = request
        self.response = response
    }

// MARK: - Properties

    public let reason: Reason

    public let request: HTTPRequest

    public let response: HTTPResponse?

// MARK: - Inner Types

    public enum Reason
    {
        case httpClientError(error: HTTPClientError)
        case httpRequestError(error: HTTPRequestError)
        case httpResponseError(error: HTTPResponseError)
    }

}

// ----------------------------------------------------------------------------

open class NestedError<T>: Error
{
// MARK: - Construction

    public init(cause: T?) {
        self.cause = cause
    }

// MARK: - Properties

    public let cause: T?

}

// ----------------------------------------------------------------------------

extension NestedError: CustomStringConvertible, CustomDebugStringConvertible
{
// MARK: - Properties

    open var description: String {
        let cause = (self.cause != nil) ? String(describing: self.cause!) : "nil"
        return "\(type(of: self))(cause: \(cause))"
    }

    open var debugDescription: String {
        return self.description
    }

}

// ----------------------------------------------------------------------------

public protocol HTTPClientError: Error { }

// ----------------------------------------------------------------------------

public protocol HTTPRequestError: Error { }

open class HTTPRequestSerializationError: NestedError<Error>, HTTPRequestError { }

// ----------------------------------------------------------------------------

public protocol HTTPResponseError: Error { }

open class HTTPResponseSerializationError: NestedError<Error>, HTTPResponseError { }
open class HTTPResponseStatusCodeError: NestedError<Error>, HTTPResponseError { }

// ----------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.2957140183417556, 'fraction_numerical': 0.0, 'mean_word_length': 1.549618320610687, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4825419', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1152, 'n_words': 306}