export function pickNonBaseParams(req) {
    // cheap version of _.omit
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { url, accessToken, organizationId, authentication, ...nonBase } = req;
    return nonBase;
}
export const unwrapError = (payload) => {
    const { response } = payload;
    if (response.body) {
        return unwrapSearchApiError(payload);
    }
    return unwrapClientError(response);
};
const unwrapSearchApiError = (payload) => {
    if (isSearchAPIException(payload)) {
        return unwrapErrorByException(payload);
    }
    if (isSearchAPIErrorWithStatusCode(payload)) {
        return payload.body;
    }
    return { message: 'unknown', statusCode: 0, type: 'unknown' };
};
const unwrapClientError = (response) => {
    // Transform an error to an object https://stackoverflow.com/a/26199752
    const body = JSON.parse(JSON.stringify(response, Object.getOwnPropertyNames(response)));
    return {
        ...body,
        message: `Client side error: ${body.message || ''}`,
        statusCode: 400,
        type: 'ClientError',
    };
};
function isSearchAPIErrorWithStatusCode(r) {
    return (r.body.statusCode !==
        undefined);
}
function isSearchAPIException(r) {
    return (r.body
        .exception !== undefined);
}
const unwrapErrorByException = (res) => ({
    message: res.body.exception.code,
    statusCode: res.response.status,
    type: res.body.exception.code,
});
