'use strict';

var Plaid = require('./Plaid-CPESyiiV.js');

// Errors on [capital]/config/locales/en.yml
// Add more errors as needed
const API_ERRORS = {
    NOT_AUTHENTICATED: 'not_authenticated',
    INVALID_PARAMETER: 'invalid_parameter',
};

const getErrorMessage = (error) => {
    if (typeof error === 'string') {
        return error;
    }
    return error.message;
};
const getErrorCode = (code) => {
    switch (code) {
        case API_ERRORS.NOT_AUTHENTICATED:
            return Plaid.ComponentErrorCodes.NOT_AUTHENTICATED;
        case API_ERRORS.INVALID_PARAMETER:
            return Plaid.ComponentErrorCodes.INVALID_PARAMETER;
        // add more cases as needed
        default:
            return Plaid.ComponentErrorCodes.FETCH_ERROR;
    }
};

exports.getErrorCode = getErrorCode;
exports.getErrorMessage = getErrorMessage;
