Skip to content

Commit 24397c5

Browse files
authored
improve logging for alt rfq request (0xProject#158)
* improve logging for alt rfq request * clean up unsuccessful status code logic * Fix quote requestor tests * get rid of unnecessary promise handling * remove unused code * update changelog * changed warning message for no quote * appease prettier
1 parent 06b3464 commit 24397c5

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

packages/asset-swapper/CHANGELOG.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
{
1414
"note": "Rename {Rfqt=>Rfq} for many types in Asset Swapper",
1515
"pr": 179
16+
},
17+
{
18+
"note": "improve logging for alt RFQ requests",
19+
"pr": 158
1620
}
1721
]
1822
},

packages/asset-swapper/src/utils/alt_mm_implementation_utils.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import {
1212
AltQuoteRequestData,
1313
AltQuoteSide,
1414
AltRfqMakerAssetOfferings,
15+
LogFunction,
1516
} from '../types';
1617

18+
const SUCCESS_CODE = 201;
19+
1720
function getAltMarketInfo(
1821
offerings: AltOffering[],
1922
buyTokenAddress: string,
@@ -122,6 +125,7 @@ export async function returnQuoteFromAltMMAsync<ResponseT>(
122125
altRfqAssetOfferings: AltRfqMakerAssetOfferings,
123126
takerRequestQueryParams: TakerRequestQueryParams,
124127
axiosInstance: AxiosInstance,
128+
warningLogger: LogFunction,
125129
cancelToken: CancelToken,
126130
): Promise<{ data: ResponseT; status: number }> {
127131
const altPair = getAltMarketInfo(
@@ -212,14 +216,44 @@ export async function returnQuoteFromAltMMAsync<ResponseT>(
212216
}
213217
}
214218

215-
const response = await axiosInstance.post(`${url}/quotes`, data, {
216-
headers: { Authorization: `Bearer ${apiKey}` },
217-
timeout: maxResponseTimeMs,
218-
cancelToken,
219-
});
219+
const response = await axiosInstance
220+
.post(`${url}/quotes`, data, {
221+
headers: { Authorization: `Bearer ${apiKey}` },
222+
timeout: maxResponseTimeMs,
223+
cancelToken,
224+
})
225+
.catch(err => {
226+
warningLogger(err, `Alt RFQ MM request failed`);
227+
throw new Error(`Alt RFQ MM request failed`);
228+
});
229+
230+
// empty response will get filtered out in validation
231+
const emptyResponse = {};
220232

233+
// tslint:disable-next-line:custom-no-magic-numbers
234+
if (response.status !== SUCCESS_CODE) {
235+
const rejectedRequestInfo = {
236+
status: response.status,
237+
message: response.data,
238+
};
239+
warningLogger(rejectedRequestInfo, `Alt RFQ MM did not return a status of ${SUCCESS_CODE}`);
240+
return {
241+
data: (emptyResponse as unknown) as ResponseT,
242+
status: response.status,
243+
};
244+
}
245+
// successful handling but no quote is indicated by status = 'rejected'
221246
if (response.data.status === 'rejected') {
222-
throw new Error('alt MM rejected quote');
247+
warningLogger(
248+
response.data.id,
249+
`Alt RFQ MM handled the request successfully but did not return a quote (status = 'rejected')`,
250+
);
251+
return {
252+
data: (emptyResponse as unknown) as ResponseT,
253+
// hack: set the http status to 204 no content so we can more
254+
// easily track when no quote is returned
255+
status: 204,
256+
};
223257
}
224258

225259
const parsedResponse =

packages/asset-swapper/src/utils/quote_requestor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
AltRfqMakerAssetOfferings,
1111
LogFunction,
1212
MarketOperation,
13-
RfqPairType,
1413
RfqMakerAssetOfferings,
14+
RfqPairType,
1515
RfqRequestOpts,
1616
SignedNativeOrder,
1717
TypedMakerUrl,
@@ -455,6 +455,7 @@ export class QuoteRequestor {
455455
options.altRfqAssetOfferings || {},
456456
requestParams,
457457
this._quoteRequestorHttpClient,
458+
this._warningLogger,
458459
cancelTokenSource.token,
459460
);
460461

packages/asset-swapper/test/quote_requestor_test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const ALT_RFQ_CREDS = {
4040
altRfqProfile: ALT_PROFILE,
4141
};
4242

43+
const CREATED_STATUS_CODE = 201;
44+
4345
function makeThreeMinuteExpiry(): BigNumber {
4446
const expiry = new Date(Date.now());
4547
expiry.setMinutes(expiry.getMinutes() + 3);
@@ -188,7 +190,7 @@ describe('QuoteRequestor', async () => {
188190
altMockedRequests.push({
189191
endpoint: 'https://132.0.0.1',
190192
mmApiKey: ALT_MM_API_KEY,
191-
responseCode: StatusCodes.Success,
193+
responseCode: CREATED_STATUS_CODE,
192194
requestData: altFirmRequestData,
193195
responseData: altFirmResponse,
194196
});
@@ -566,7 +568,7 @@ describe('QuoteRequestor', async () => {
566568
altMockedRequests.push({
567569
endpoint: 'https://132.0.0.1',
568570
mmApiKey: ALT_MM_API_KEY,
569-
responseCode: StatusCodes.Success,
571+
responseCode: CREATED_STATUS_CODE,
570572
requestData: buyAmountAltRequest,
571573
responseData: buyAmountAltResponse,
572574
});
@@ -612,7 +614,7 @@ describe('QuoteRequestor', async () => {
612614
altMockedRequests.push({
613615
endpoint: 'https://132.0.0.1',
614616
mmApiKey: ALT_MM_API_KEY,
615-
responseCode: StatusCodes.Success,
617+
responseCode: CREATED_STATUS_CODE,
616618
requestData: buyValueAltRequest,
617619
responseData: buyValueAltResponse,
618620
});
@@ -658,7 +660,7 @@ describe('QuoteRequestor', async () => {
658660
altMockedRequests.push({
659661
endpoint: 'https://132.0.0.1',
660662
mmApiKey: ALT_MM_API_KEY,
661-
responseCode: StatusCodes.Success,
663+
responseCode: CREATED_STATUS_CODE,
662664
requestData: sellAmountAltRequest,
663665
responseData: sellAmountAltResponse,
664666
});
@@ -704,7 +706,7 @@ describe('QuoteRequestor', async () => {
704706
altMockedRequests.push({
705707
endpoint: 'https://132.0.0.1',
706708
mmApiKey: ALT_MM_API_KEY,
707-
responseCode: StatusCodes.Success,
709+
responseCode: CREATED_STATUS_CODE,
708710
requestData: sellValueAltRequest,
709711
responseData: sellValueAltResponse,
710712
});

0 commit comments

Comments
 (0)