Skip to content

Commit

Permalink
check if error is related to order replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyaoy committed Jun 12, 2024
1 parent 592b164 commit 2a7d020
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('stateful-order-replacement-handler', () => {

expect(logger.error).toHaveBeenCalledWith(expect.objectContaining({
at: 'StatefulOrderReplacementHandler#handleOrderReplacement',
message: 'Unable to cancel replaced order because orderId not found',
message: 'StatefulOrderReplacementHandler#Unable to cancel replaced order because orderId not found',
orderId: defaultStatefulOrderReplacementEvent.orderReplacement!.oldOrderId,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ export class StatefulOrderReplacementHandler
const oldOrderId = this.event.orderReplacement!.oldOrderId!;
const order = this.event.orderReplacement!.order!;

// Only one error is expected that's related to order replacement.
// If more errors are added to `dydx_stateful_order_handler.sql`, this will need to be updated.
if (resultRow.errors != null) {
logger.error({
at: 'StatefulOrderReplacementHandler#handleOrderReplacement',
message: resultRow.errors[0],
orderId: oldOrderId,
});
stats.increment(`${config.SERVICE_NAME}.handle_stateful_order_replacement.old_order_id_not_found_in_db`, 1);
// We expect the first error to be related to order replacement.
// If more errors are added to `dydx_stateful_order_handler.sql`, this may need to be updated
const errorMessage = resultRow.errors[0];
if (errorMessage.includes('StatefulOrderReplacementHandler#')) {
logger.error({
at: 'StatefulOrderReplacementHandler#handleOrderReplacement',
message: errorMessage,
orderId: oldOrderId,
});
stats.increment(`${config.SERVICE_NAME}.handle_stateful_order_replacement.old_order_id_not_found_in_db`, 1);
}
}

return this.createKafkaEvents(oldOrderId, order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ BEGIN
RETURNING * INTO order_record;

IF NOT FOUND THEN
errors_response = array_append(errors_response, '"Unable to cancel replaced order because orderId not found"'::jsonb);
errors_response = array_append(errors_response, '"StatefulOrderReplacementHandler#Unable to cancel replaced order because orderId not found"'::jsonb);
END IF;
END IF;
order_record := NULL; /* Reset order_record so the order place below doesn't carry over any values set above. */
Expand Down

0 comments on commit 2a7d020

Please sign in to comment.