<commit_before>import Vapor

/// Errors that can be thrown during authentication
public enum AuthenticationError: String, Error {
    case signingError
    case userNotFound
    case weakPassword
    case usernameAlreadyExists
    case incorrectPassword
    case incorrectOldPassword
    case passwordWithoutUsernameOrOldPassword
}

// MARK: - AbortError
extension AuthenticationError: AbortError {

    /// See `AbortError.status`
    public var status: HTTPResponseStatus {
        switch self {
        case .signingError                          : return .internalServerError
        case .userNotFound                          : return .unauthorized
        case .weakPassword                          : return .unprocessableEntity
        case .usernameAlreadyExists                 : return .unprocessableEntity
        case .incorrectPassword                     : return .unauthorized
        case .incorrectOldPassword                  : return .unauthorized
        case .passwordWithoutUsernameOrOldPassword  : return .unprocessableEntity
        }
    }

    /// See `AbortError.reason`
    public var reason: String {
        switch self {
        case .signingError:
            return "Could not convert signed JWT into String."
        case .userNotFound:
            return "Could not find user."
        case .weakPassword:
            return "The supplied password did not meet the password strength requirements."
        case .usernameAlreadyExists:
            return "A user with the supplied username already exists."
        case .incorrectPassword:
            return "Incorrect password given."
        case .incorrectOldPassword:
            return "Incorrect old password."
        case .passwordWithoutUsernameOrOldPassword:
            return "Password should only be provided when updating it or updating the username."
        }
    }
}

// MARK: - Debuggable
extension AuthenticationError: Debuggable {

    /// See `Debuggable.identifier`
    public var identifier: String {
        return rawValue
    }
}<commit_msg>Add malformed payload error to Sugar<commit_after>import Vapor

/// Errors that can be thrown during authentication
public enum AuthenticationError: String, Error {
    case signingError
    case userNotFound
    case weakPassword
    case usernameAlreadyExists
    case incorrectPassword
    case incorrectOldPassword
    case passwordWithoutUsernameOrOldPassword
    case malformedPayload
}

// MARK: - AbortError
extension AuthenticationError: AbortError {

    /// See `AbortError.status`
    public var status: HTTPResponseStatus {
        switch self {
        case .signingError                          : return .internalServerError
        case .userNotFound                          : return .unauthorized
        case .weakPassword                          : return .unprocessableEntity
        case .usernameAlreadyExists                 : return .unprocessableEntity
        case .incorrectPassword                     : return .unauthorized
        case .incorrectOldPassword                  : return .unauthorized
        case .passwordWithoutUsernameOrOldPassword  : return .unprocessableEntity
        case .malformedPayload                      : return .badRequest
        }
    }

    /// See `AbortError.reason`
    public var reason: String {
        switch self {
        case .signingError:
            return "Could not convert signed JWT into String."
        case .userNotFound:
            return "Could not find user."
        case .weakPassword:
            return "The supplied password did not meet the password strength requirements."
        case .usernameAlreadyExists:
            return "A user with the supplied username already exists."
        case .incorrectPassword:
            return "Incorrect password given."
        case .incorrectOldPassword:
            return "Incorrect old password."
        case .passwordWithoutUsernameOrOldPassword:
            return "Password should only be provided when updating it or updating the username."
        case .malformedPayload:
            return "Malformed JWT payload received."
        }
    }
}

// MARK: - Debuggable
extension AuthenticationError: Debuggable {

    /// See `Debuggable.identifier`
    public var identifier: String {
        return rawValue
    }
}
{'fraction_non_alphanumeric': 0.05330243337195829, 'fraction_numerical': 0.0, 'mean_word_length': 2.0372976776917664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3867234', 'n_tokens_mistral': 980, 'n_tokens_neox': 957, 'n_words': 334}