Skip to content

Commit

Permalink
Merge pull request #307 from Uniswap/fix-try-catch
Browse files Browse the repository at this point in the history
fix: try catch in handler instead
  • Loading branch information
ConjunctiveNormalForm authored Apr 11, 2024
2 parents 342e9bf + e28b29a commit c6cd013
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
18 changes: 9 additions & 9 deletions lib/handlers/hard-quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ export class QuoteHandler extends APIGLambdaHandler<
metric.putMetric(Metric.QUOTE_POST_ATTEMPT, 1, MetricLoggerUnit.Count);
// if no quote and creating open order, create random new quoteId
await orderServiceProvider.postOrder(cosignedOrder, request.innerSig, bestQuote?.quoteId ?? uuidv4());
metric.putMetric(Metric.QUOTE_200, 1, MetricLoggerUnit.Count);
metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds);
const response = new HardQuoteResponse(request, cosignedOrder);

return {
statusCode: 200,
body: response.toResponseJSON(),
};
} catch (e) {
log.error({ error: e }, 'Error posting order');
metric.putMetric(Metric.QUOTE_400, 1, MetricLoggerUnit.Count);
metric.putMetric(Metric.QUOTE_POST_ERROR, 1, MetricLoggerUnit.Count);
throw new OrderPostError();
}

metric.putMetric(Metric.QUOTE_200, 1, MetricLoggerUnit.Count);
metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds);
const response = new HardQuoteResponse(request, cosignedOrder);

return {
statusCode: 200,
body: response.toResponseJSON(),
};
}

protected requestBodySchema(): Joi.ObjectSchema | null {
Expand Down
29 changes: 12 additions & 17 deletions lib/providers/order/uniswapxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@ export class UniswapXServiceProvider implements OrderServiceProvider {
const axiosConfig = {
timeout: ORDER_SERVICE_TIMEOUT_MS,
};

try {
await axios.post(
`${this.uniswapxServiceUrl}dutch-auction/order`,
{
encodedOrder: order.serialize(),
signature: signature,
chainId: order.chainId,
quoteId: quoteId,
orderType: V2_ORDER_TYPE,
},
axiosConfig
);
this.log.info({ orderHash: order.hash() }, 'Order posted to UniswapX Service');
} catch (e) {
this.log.error({ error: e }, 'Error posting order to UniswapX Service');
}
await axios.post(
`${this.uniswapxServiceUrl}dutch-auction/order`,
{
encodedOrder: order.serialize(),
signature: signature,
chainId: order.chainId,
quoteId: quoteId,
orderType: V2_ORDER_TYPE,
},
axiosConfig
);
this.log.info({ orderHash: order.hash() }, 'Order posted to UniswapX Service');
}
}

0 comments on commit c6cd013

Please sign in to comment.