Skip to content

Commit

Permalink
refact: improve transferwise debug
Browse files Browse the repository at this point in the history
  • Loading branch information
kewitz committed Mar 19, 2021
1 parent e62d0b6 commit d2001ec
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/lib/transferwise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const compactRecipientDetails = <T>(object: T): Partial<T> => <Partial<T>>omitBy
const getData = <T extends { data?: Record<string, unknown> }>(obj: T | undefined): T['data'] | undefined =>
obj && obj.data;

const tap = fn => data => {
fn(data);
return data;
};

const parseError = (
error: AxiosError<{ errorCode?: TransferwiseErrorCodes; errors?: Record<string, unknown>[] }>,
defaultMessage?: string,
Expand Down Expand Up @@ -95,10 +100,11 @@ export const requestDataAndThrowParsedError = (
},
defaultErrorMessage?: string,
): Promise<any> => {
debug(`calling ${url}`);
debug(`calling ${url}: ${JSON.stringify({ data, params: options.params }, null, 2)}`);
const pRequest = data ? fn(url, data, options) : fn(url, options);
return pRequest
.then(getData)
.then(tap(data => debug(JSON.stringify(data, null, 2))))
.catch(e => {
// Implements Strong Customer Authentication
// https://api-docs.transferwise.com/#payouts-guide-strong-customer-authentication
Expand Down

0 comments on commit d2001ec

Please sign in to comment.