diff --git a/dist/providers/BaseProvider/index.js b/dist/providers/BaseProvider/index.js index 98b7ace..618329c 100644 --- a/dist/providers/BaseProvider/index.js +++ b/dist/providers/BaseProvider/index.js @@ -46,11 +46,12 @@ class BaseProvider { } configureResponses() { this.Api.interceptors.response.use(response => { - this.log('RESPONSE:', typeof response?.data, response?.data); - if (response?.data && typeof response?.data === 'string') { - return (0, camelcase_keys_1.default)((0, onResponseError_1.convertStringResponseData)(response?.data), { deep: true }); + const data = response?.data || response; + this.log(`RESPONSE: (${response?.statusText})`, typeof data, data); + if (data && typeof data === 'string') { + return (0, camelcase_keys_1.default)((0, onResponseError_1.convertStringResponseData)(data), { deep: true }); } - return (0, camelcase_keys_1.default)(response.data, { deep: true }); + return (0, camelcase_keys_1.default)(data, { deep: true }); }, onResponseError_1.onResponseError); return this; } diff --git a/dist/providers/BaseProvider/onResponseError.js b/dist/providers/BaseProvider/onResponseError.js index 4cb03dd..ad5aa44 100644 --- a/dist/providers/BaseProvider/onResponseError.js +++ b/dist/providers/BaseProvider/onResponseError.js @@ -12,6 +12,10 @@ async function onResponseError(error) { const data = Object.assign({}, result, convertStringResponseData(response)); return Promise.resolve({ data }); } + if (typeof response?.data === 'string') { + const data = Object.assign({}, result, convertStringResponseData(response?.data)); + return Promise.resolve({ data }); + } result.message = `httpError ${statusHttp}`; return Promise.resolve({ data: result }); } diff --git a/dist/providers/SacDigital/index.js b/dist/providers/SacDigital/index.js index 42d51c4..a25f49d 100644 --- a/dist/providers/SacDigital/index.js +++ b/dist/providers/SacDigital/index.js @@ -142,6 +142,8 @@ class SacDigital extends BaseProvider_1.BaseProvider { return this.buildError('API is not ready'); } async sendNotification(payload) { + if (!payload?.contact) + return this.buildError('no contact informed'); try { const res = await this.apiPost(constants_1.ReqType.NOTIFICATION, payload); return (0, dto_1.responseSendingDto)(res); diff --git a/src/providers/BaseProvider/index.ts b/src/providers/BaseProvider/index.ts index 880f435..b7cbe98 100644 --- a/src/providers/BaseProvider/index.ts +++ b/src/providers/BaseProvider/index.ts @@ -67,11 +67,12 @@ export class BaseProvider { protected configureResponses() { this.Api.interceptors.response.use(response => { - this.log('RESPONSE:', typeof response?.data, response?.data); - if (response?.data && typeof response?.data === 'string') { - return camelcaseKeys(convertStringResponseData(response?.data), { deep: true }); + const data = response?.data || response; + this.log(`RESPONSE: (${response?.statusText})`, typeof data, data); + if (data && typeof data === 'string') { + return camelcaseKeys(convertStringResponseData(data), { deep: true }); } - return camelcaseKeys(response.data, { deep: true }); + return camelcaseKeys(data, { deep: true }); }, onResponseError); return this; } diff --git a/src/providers/BaseProvider/onResponseError.ts b/src/providers/BaseProvider/onResponseError.ts index 06ffb69..687138e 100644 --- a/src/providers/BaseProvider/onResponseError.ts +++ b/src/providers/BaseProvider/onResponseError.ts @@ -21,6 +21,11 @@ export async function onResponseError(error?: AxiosError): Promise<{ data: IResu return Promise.resolve({ data }); } + if (typeof response?.data === 'string') { + const data = Object.assign({}, result, convertStringResponseData(response?.data)); + return Promise.resolve({ data }); + } + result.message = `httpError ${statusHttp}`; return Promise.resolve({ data: result }); } diff --git a/src/providers/SacDigital/index.ts b/src/providers/SacDigital/index.ts index dcde837..dad138e 100644 --- a/src/providers/SacDigital/index.ts +++ b/src/providers/SacDigital/index.ts @@ -173,6 +173,7 @@ export class SacDigital extends BaseProvider implements IProvider { } private async sendNotification(payload: ISacDigitalRequestSend): Promise { + if (!payload?.contact) return this.buildError('no contact informed'); try { const res = await this.apiPost(ReqType.NOTIFICATION, payload); return responseSendingDto(res);