Skip to content

Commit

Permalink
feat: implement granular error handling in plugin-coinbase
Browse files Browse the repository at this point in the history
  • Loading branch information
monilpat committed Jan 5, 2025
1 parent 7e5089c commit 0562fb4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
32 changes: 21 additions & 11 deletions packages/plugin-coinbase/advanced-sdk-ts/src/rest/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ export function getAccount(
this: RESTBase,
{ accountUuid }: GetAccountRequest
): Promise<GetAccountResponse> {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/accounts/${accountUuid}`,
isPublic: false,
});
try {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/accounts/${accountUuid}`,
isPublic: false,
});
} catch (error) {
console.error('Error fetching account:', error);
throw error;
}
}

// [GET] List Accounts
Expand All @@ -27,10 +32,15 @@ export function listAccounts(
this: RESTBase,
requestParams: ListAccountsRequest
): Promise<ListAccountsResponse> {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/accounts`,
queryParams: requestParams,
isPublic: false,
});
try {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/accounts`,
queryParams: requestParams,
isPublic: false,
});
} catch (error) {
console.error('Error listing accounts:', error);
throw error;
}
}
53 changes: 34 additions & 19 deletions packages/plugin-coinbase/advanced-sdk-ts/src/rest/converts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ export function createConvertQuote(
this: RESTBase,
requestParams: CreateConvertQuoteRequest
): Promise<CreateConvertQuoteResponse> {
return this.request({
method: method.POST,
endpoint: `${API_PREFIX}/convert/quote`,
bodyParams: requestParams,
isPublic: false,
});
try {
return this.request({
method: method.POST,
endpoint: `${API_PREFIX}/convert/quote`,
bodyParams: requestParams,
isPublic: false,
});
} catch (error) {
console.error('Error creating convert quote:', error);
throw error;
}
}

// [GET] Get Convert Trade
Expand All @@ -30,24 +35,34 @@ export function getConvertTrade(
this: RESTBase,
{ tradeId, ...requestParams }: GetConvertTradeRequest
): Promise<GetConvertTradeResponse> {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/convert/trade/${tradeId}`,
queryParams: requestParams,
isPublic: false,
});
try {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/convert/trade/${tradeId}`,
queryParams: requestParams,
isPublic: false,
});
} catch (error) {
console.error('Error fetching convert trade:', error);
throw error;
}
}

// [POST] Commit Connvert Trade
// [POST] Commit Convert Trade
// https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_commitconverttrade
export function commitConvertTrade(
this: RESTBase,
{ tradeId, ...requestParams }: CommitConvertTradeRequest
): Promise<CommitConvertTradeResponse> {
return this.request({
method: method.POST,
endpoint: `${API_PREFIX}/convert/trade/${tradeId}`,
bodyParams: requestParams,
isPublic: false,
});
try {
return this.request({
method: method.POST,
endpoint: `${API_PREFIX}/convert/trade/${tradeId}`,
bodyParams: requestParams,
isPublic: false,
});
} catch (error) {
console.error('Error committing convert trade:', error);
throw error;
}
}
16 changes: 10 additions & 6 deletions packages/plugin-coinbase/advanced-sdk-ts/src/rest/dataAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { API_PREFIX } from '../constants';
import { RESTBase } from './rest-base';

import { method } from './types/request-types';
import { GetAPIKeyPermissionsResponse } from './types/dataAPI-types';

Expand All @@ -9,9 +8,14 @@ import { GetAPIKeyPermissionsResponse } from './types/dataAPI-types';
export function getAPIKeyPermissions(
this: RESTBase
): Promise<GetAPIKeyPermissionsResponse> {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/key_permissions`,
isPublic: false,
});
try {
return this.request({
method: method.GET,
endpoint: `${API_PREFIX}/key_permissions`,
isPublic: false,
});
} catch (error) {
console.error('Error fetching API Key Permissions:', error);
throw error;
}
}

0 comments on commit 0562fb4

Please sign in to comment.