improve logging for alt rfq request (#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
This commit is contained in:
parent
06b3464756
commit
24397c51a8
@ -13,6 +13,10 @@
|
|||||||
{
|
{
|
||||||
"note": "Rename {Rfqt=>Rfq} for many types in Asset Swapper",
|
"note": "Rename {Rfqt=>Rfq} for many types in Asset Swapper",
|
||||||
"pr": 179
|
"pr": 179
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"note": "improve logging for alt RFQ requests",
|
||||||
|
"pr": 158
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -12,8 +12,11 @@ import {
|
|||||||
AltQuoteRequestData,
|
AltQuoteRequestData,
|
||||||
AltQuoteSide,
|
AltQuoteSide,
|
||||||
AltRfqMakerAssetOfferings,
|
AltRfqMakerAssetOfferings,
|
||||||
|
LogFunction,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
|
const SUCCESS_CODE = 201;
|
||||||
|
|
||||||
function getAltMarketInfo(
|
function getAltMarketInfo(
|
||||||
offerings: AltOffering[],
|
offerings: AltOffering[],
|
||||||
buyTokenAddress: string,
|
buyTokenAddress: string,
|
||||||
@ -122,6 +125,7 @@ export async function returnQuoteFromAltMMAsync<ResponseT>(
|
|||||||
altRfqAssetOfferings: AltRfqMakerAssetOfferings,
|
altRfqAssetOfferings: AltRfqMakerAssetOfferings,
|
||||||
takerRequestQueryParams: TakerRequestQueryParams,
|
takerRequestQueryParams: TakerRequestQueryParams,
|
||||||
axiosInstance: AxiosInstance,
|
axiosInstance: AxiosInstance,
|
||||||
|
warningLogger: LogFunction,
|
||||||
cancelToken: CancelToken,
|
cancelToken: CancelToken,
|
||||||
): Promise<{ data: ResponseT; status: number }> {
|
): Promise<{ data: ResponseT; status: number }> {
|
||||||
const altPair = getAltMarketInfo(
|
const altPair = getAltMarketInfo(
|
||||||
@ -212,14 +216,44 @@ export async function returnQuoteFromAltMMAsync<ResponseT>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axiosInstance.post(`${url}/quotes`, data, {
|
const response = await axiosInstance
|
||||||
|
.post(`${url}/quotes`, data, {
|
||||||
headers: { Authorization: `Bearer ${apiKey}` },
|
headers: { Authorization: `Bearer ${apiKey}` },
|
||||||
timeout: maxResponseTimeMs,
|
timeout: maxResponseTimeMs,
|
||||||
cancelToken,
|
cancelToken,
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
warningLogger(err, `Alt RFQ MM request failed`);
|
||||||
|
throw new Error(`Alt RFQ MM request failed`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// empty response will get filtered out in validation
|
||||||
|
const emptyResponse = {};
|
||||||
|
|
||||||
|
// tslint:disable-next-line:custom-no-magic-numbers
|
||||||
|
if (response.status !== SUCCESS_CODE) {
|
||||||
|
const rejectedRequestInfo = {
|
||||||
|
status: response.status,
|
||||||
|
message: response.data,
|
||||||
|
};
|
||||||
|
warningLogger(rejectedRequestInfo, `Alt RFQ MM did not return a status of ${SUCCESS_CODE}`);
|
||||||
|
return {
|
||||||
|
data: (emptyResponse as unknown) as ResponseT,
|
||||||
|
status: response.status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// successful handling but no quote is indicated by status = 'rejected'
|
||||||
if (response.data.status === 'rejected') {
|
if (response.data.status === 'rejected') {
|
||||||
throw new Error('alt MM rejected quote');
|
warningLogger(
|
||||||
|
response.data.id,
|
||||||
|
`Alt RFQ MM handled the request successfully but did not return a quote (status = 'rejected')`,
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
data: (emptyResponse as unknown) as ResponseT,
|
||||||
|
// hack: set the http status to 204 no content so we can more
|
||||||
|
// easily track when no quote is returned
|
||||||
|
status: 204,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedResponse =
|
const parsedResponse =
|
||||||
|
@ -10,8 +10,8 @@ import {
|
|||||||
AltRfqMakerAssetOfferings,
|
AltRfqMakerAssetOfferings,
|
||||||
LogFunction,
|
LogFunction,
|
||||||
MarketOperation,
|
MarketOperation,
|
||||||
RfqPairType,
|
|
||||||
RfqMakerAssetOfferings,
|
RfqMakerAssetOfferings,
|
||||||
|
RfqPairType,
|
||||||
RfqRequestOpts,
|
RfqRequestOpts,
|
||||||
SignedNativeOrder,
|
SignedNativeOrder,
|
||||||
TypedMakerUrl,
|
TypedMakerUrl,
|
||||||
@ -455,6 +455,7 @@ export class QuoteRequestor {
|
|||||||
options.altRfqAssetOfferings || {},
|
options.altRfqAssetOfferings || {},
|
||||||
requestParams,
|
requestParams,
|
||||||
this._quoteRequestorHttpClient,
|
this._quoteRequestorHttpClient,
|
||||||
|
this._warningLogger,
|
||||||
cancelTokenSource.token,
|
cancelTokenSource.token,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ const ALT_RFQ_CREDS = {
|
|||||||
altRfqProfile: ALT_PROFILE,
|
altRfqProfile: ALT_PROFILE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CREATED_STATUS_CODE = 201;
|
||||||
|
|
||||||
function makeThreeMinuteExpiry(): BigNumber {
|
function makeThreeMinuteExpiry(): BigNumber {
|
||||||
const expiry = new Date(Date.now());
|
const expiry = new Date(Date.now());
|
||||||
expiry.setMinutes(expiry.getMinutes() + 3);
|
expiry.setMinutes(expiry.getMinutes() + 3);
|
||||||
@ -188,7 +190,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
altMockedRequests.push({
|
altMockedRequests.push({
|
||||||
endpoint: 'https://132.0.0.1',
|
endpoint: 'https://132.0.0.1',
|
||||||
mmApiKey: ALT_MM_API_KEY,
|
mmApiKey: ALT_MM_API_KEY,
|
||||||
responseCode: StatusCodes.Success,
|
responseCode: CREATED_STATUS_CODE,
|
||||||
requestData: altFirmRequestData,
|
requestData: altFirmRequestData,
|
||||||
responseData: altFirmResponse,
|
responseData: altFirmResponse,
|
||||||
});
|
});
|
||||||
@ -566,7 +568,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
altMockedRequests.push({
|
altMockedRequests.push({
|
||||||
endpoint: 'https://132.0.0.1',
|
endpoint: 'https://132.0.0.1',
|
||||||
mmApiKey: ALT_MM_API_KEY,
|
mmApiKey: ALT_MM_API_KEY,
|
||||||
responseCode: StatusCodes.Success,
|
responseCode: CREATED_STATUS_CODE,
|
||||||
requestData: buyAmountAltRequest,
|
requestData: buyAmountAltRequest,
|
||||||
responseData: buyAmountAltResponse,
|
responseData: buyAmountAltResponse,
|
||||||
});
|
});
|
||||||
@ -612,7 +614,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
altMockedRequests.push({
|
altMockedRequests.push({
|
||||||
endpoint: 'https://132.0.0.1',
|
endpoint: 'https://132.0.0.1',
|
||||||
mmApiKey: ALT_MM_API_KEY,
|
mmApiKey: ALT_MM_API_KEY,
|
||||||
responseCode: StatusCodes.Success,
|
responseCode: CREATED_STATUS_CODE,
|
||||||
requestData: buyValueAltRequest,
|
requestData: buyValueAltRequest,
|
||||||
responseData: buyValueAltResponse,
|
responseData: buyValueAltResponse,
|
||||||
});
|
});
|
||||||
@ -658,7 +660,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
altMockedRequests.push({
|
altMockedRequests.push({
|
||||||
endpoint: 'https://132.0.0.1',
|
endpoint: 'https://132.0.0.1',
|
||||||
mmApiKey: ALT_MM_API_KEY,
|
mmApiKey: ALT_MM_API_KEY,
|
||||||
responseCode: StatusCodes.Success,
|
responseCode: CREATED_STATUS_CODE,
|
||||||
requestData: sellAmountAltRequest,
|
requestData: sellAmountAltRequest,
|
||||||
responseData: sellAmountAltResponse,
|
responseData: sellAmountAltResponse,
|
||||||
});
|
});
|
||||||
@ -704,7 +706,7 @@ describe('QuoteRequestor', async () => {
|
|||||||
altMockedRequests.push({
|
altMockedRequests.push({
|
||||||
endpoint: 'https://132.0.0.1',
|
endpoint: 'https://132.0.0.1',
|
||||||
mmApiKey: ALT_MM_API_KEY,
|
mmApiKey: ALT_MM_API_KEY,
|
||||||
responseCode: StatusCodes.Success,
|
responseCode: CREATED_STATUS_CODE,
|
||||||
requestData: sellValueAltRequest,
|
requestData: sellValueAltRequest,
|
||||||
responseData: sellValueAltResponse,
|
responseData: sellValueAltResponse,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user