<commit_before>package com.auth0.exception;

import java.util.Collections;
import java.util.Map;

/**
 * Class that represents an Auth0 Server error captured from a http response. Provides different methods to get a clue of why the request failed.
 * i.e.:
 * <pre>
 * {@code
 * {
 *      statusCode: 400,
 *      description: "Query validation error: 'String 'users' does not match pattern. Must be a comma separated list of the following values: name,strategy,options,enabled_clients,id,provisioning_ticket_url' on property fields (A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields).",
 *      error: "invalid_query_string"
 * }
 * }
 * </pre>
 */
@SuppressWarnings("WeakerAccess")
public class APIException extends Auth0Exception {

    private String error;
    private String description;
    private int statusCode;
    private Map<String, Object> values;

    public APIException(String payload, int statusCode, Throwable cause) {
        super(createMessage(payload, statusCode), cause);
        this.description = payload;
        this.statusCode = statusCode;
    }

    public APIException(Map<String, Object> values, int statusCode) {
        super(createMessage(obtainExceptionMessage(values), statusCode));
        this.values = Collections.unmodifiableMap(values);
        this.error = obtainExceptionError(values);
        this.description = obtainExceptionMessage(values);
        this.statusCode = statusCode;
    }

    /**
     * Getter for the Http Status Code received in the response.
     * i.e. a {@code status_code=403} would mean that the token has an insufficient scope.
     *
     * @return the status code.
     */
    public int getStatusCode() {
        return statusCode;
    }

    /**<commit_msg>use unmmodifiable map when possible<commit_after>package com.auth0.exception;

import java.util.Collections;
import java.util.Map;

/**
 * Class that represents an Auth0 Server error captured from a http response. Provides different methods to get a clue of why the request failed.
 * i.e.:
 * <pre>
 * {@code
 * {
 *      statusCode: 400,
 *      description: "Query validation error: 'String 'users' does not match pattern. Must be a comma separated list of the following values: name,strategy,options,enabled_clients,id,provisioning_ticket_url' on property fields (A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields).",
 *      error: "invalid_query_string"
 * }
 * }
 * </pre>
 */
@SuppressWarnings("WeakerAccess")
public class APIException extends Auth0Exception {

    private String error;
    private String description;
    private int statusCode;
    private Map<String, Object> values;

    public APIException(String payload, int statusCode, Throwable cause) {
        super(createMessage(payload, statusCode), cause);
        this.description = payload;
        this.statusCode = statusCode;
    }

    public APIException(Map<String, Object> values, int statusCode) {
        super(createMessage(obtainExceptionMessage(values), statusCode));
        this.values = Collections.unmodifiableMap(values);
        this.error = obtainExceptionError(this.values);
        this.description = obtainExceptionMessage(this.values);
        this.statusCode = statusCode;
    }

    /**
     * Getter for the Http Status Code received in the response.
     * i.e. a {@code status_code=403} would mean that the token has an insufficient scope.
     *
     * @return the status code.
     */
    public int getStatusCode() {
        return statusCode;
    }

    /**
{'fraction_non_alphanumeric': 0.09021323127392017, 'fraction_numerical': 0.004920721705850191, 'mean_word_length': 3.445929526123937, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5895152', 'n_tokens_mistral': 983, 'n_tokens_neox': 961, 'n_words': 332}