From 7bea9fe66e3af81c5522f46a92419eefafbaf4ea Mon Sep 17 00:00:00 2001 From: Mark Silva Date: Wed, 3 May 2023 14:08:07 +0800 Subject: [PATCH] REFACTOR: revised response formatting --- README.md | 2 +- src/api/client.ts | 60 ++++++++++++++++++++--------------------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index ea577b6..06ab4c6 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ import { GetTransactionsForAccountFull, TransactionRequestAccountBody, CreateTransactionRequestAccount, -} from "obp-typescript/src"; +} from "obp-typescript"; (async () => { const directLogin: DirectLoginAuthentication = { diff --git a/src/api/client.ts b/src/api/client.ts index e581615..eda6742 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -299,14 +299,12 @@ export const getRequest = async ( ): Promise => { const pathUri = uri(config, path); const header = await getOauthHeader(config, path, pathUri); - return JSON.parse( - ( - await superagent - .get(pathUri) - .set("Authorization", header) - .catch((error) => error.response) - ).text - ); + return ( + await superagent + .get(pathUri) + .set("Authorization", header) + .catch((error) => error.response) + ).body; }; /** @@ -328,15 +326,13 @@ export const postRequest = async ( ): Promise => { const pathUri = uri(config, path); const header = await getOauthHeader(config, path, pathUri); - return JSON.parse( - ( - await superagent - .post(pathUri) - .set("Authorization", header) - .send(body) - .catch((error) => error.response) - ).text - ); + return ( + await superagent + .post(pathUri) + .set("Authorization", header) + .send(body) + .catch((error) => error.response) + ).body; }; /** @@ -358,15 +354,13 @@ export const putRequest = async ( ): Promise => { const pathUri = uri(config, path); const header = await getOauthHeader(config, path, pathUri); - return JSON.parse( - ( - await superagent - .put(pathUri) - .set("Authorization", header) - .send(body) - .catch((error) => error.response) - ).text - ); + return ( + await superagent + .put(pathUri) + .set("Authorization", header) + .send(body) + .catch((error) => error.response) + ).body; }; /** @@ -387,14 +381,12 @@ export const deleteRequest = async ( ): Promise => { const pathUri = uri(config, path); const header = await getOauthHeader(config, path, pathUri); - return JSON.parse( - ( - await superagent - .delete(pathUri) - .set("Authorization", header) - .catch((error) => error.response) - ).text - ); + return ( + await superagent + .delete(pathUri) + .set("Authorization", header) + .catch((error) => error.response) + ).body; }; /**