Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const response = await this._axios.post(
path,
// we can't apply a deep snake_case transform here
// because it accept only PascalCase for keyboard and rich media
snakecaseKeys(body, { deep: false })
);
const { config, request } = response;
const data = (camelcaseKeysDeep(
response.data
) as any) as Types.ResponseData;
if (data.status !== 0) {
throw new AxiosError(`Viber API - ${data.statusMessage}`, {
config,
request,
response,
});
}
return data;
} catch (err) {
throw new AxiosError(err.message, err);
}
}
function handleError(err: AxiosError): void {
if (err.response && err.response.data) {
const error = get(err, 'response.data.error', {});
const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`;
throw new AxiosError(msg, err);
}
throw new AxiosError(err.message, err);
}
const data = (camelcaseKeysDeep(
response.data
) as any) as Types.ResponseData;
if (data.status !== 0) {
throw new AxiosError(`Viber API - ${data.statusMessage}`, {
config,
request,
response,
});
}
return data;
} catch (err) {
throw new AxiosError(err.message, err);
}
}
response.data
) as any) as Types.OAuthAPIResponse;
if (!data.ok) {
const { config, request } = response;
throw new AxiosError(`Slack API - ${data.error}`, {
config,
request,
response,
});
}
return data;
} catch (err) {
throw new AxiosError(err.message, err);
}
}
function throwWhenNotSuccess(res: {
data: {
returnCode: string;
returnMessage: string;
info?: any;
};
}): any | never {
if (res.data.returnCode !== '0000') {
const { returnCode, returnMessage } = res.data;
const msg = `LINE PAY API - ${returnCode} ${returnMessage}`;
throw new AxiosError(msg);
}
return res.data.info;
}
function handleError(err) {
const { error } = err.response.data;
const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`;
throw new AxiosError(msg, err);
}
function handleError(err: AxiosError): void {
if (err.response && err.response.data) {
const error = get(err, 'response.data.error', {});
const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`;
throw new AxiosError(msg, err);
}
throw new AxiosError(err.message, err);
}
message: string;
}[];
};
};
}): never {
if (err.response && err.response.data) {
const { message, details } = err.response.data;
let msg = `LINE API - ${message}`;
if (details && details.length > 0) {
details.forEach(detail => {
msg += `\n- ${detail.property}: ${detail.message}`;
});
}
throw new AxiosError(msg, err);
}
throw new AxiosError(err.message, err);
}
response,
});
}
if (isPlainObject(data.result) || Array.isArray(data.result)) {
return camelcaseKeysDeep(data.result);
}
return data.result;
} catch (err) {
if (err.response && err.response.data) {
const { error_code, description } = err.response.data;
const msg = `Telegram API - ${error_code} ${description || ''}`;
throw new AxiosError(msg, err);
}
throw new AxiosError(err.message, err);
}
}