Skip to content

Commit

Permalink
Merge pull request #868 from ExchangeUnion/orderbook-swap-error
Browse files Browse the repository at this point in the history
refactor(orderbook): throw error on non-swap fail
  • Loading branch information
sangaman committed Apr 5, 2019
2 parents 0991bbc + 9fc14c6 commit cfe51ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/lndclient/LndClient.ts
Expand Up @@ -343,7 +343,7 @@ class LndClient extends BaseClient {
request.setPubKey(destination);
try {
const routes = (await this.queryRoutes(request)).getRoutesList();
this.logger.debug(`got ${routes.length} route(s) to destination: ${routes}`);
this.logger.debug(`got ${routes.length} route(s) to destination ${destination}: ${routes}`);
return routes;
} catch (err) {
if (typeof err.message === 'string' && (
Expand Down
30 changes: 14 additions & 16 deletions lib/orderbook/OrderBook.ts
Expand Up @@ -374,27 +374,25 @@ class OrderBook extends EventEmitter {
onUpdate && onUpdate({ type: PlaceOrderEventType.SwapSuccess, payload: swapResult });
} catch (err) {
const failMsg = `swap for ${portion.quantity} failed during order matching`;
let failureReason: SwapFailureReason;
if (typeof err === 'number') {
if (typeof err === 'number' && SwapFailureReason[err] !== undefined) {
// treat the error as a SwapFailureReason
this.logger.warn(`${failMsg} due to ${SwapFailureReason[err]}, will repeat matching routine for failed quantity`);
failureReason = err;

const swapFailure: SwapFailure = {
failureReason: err,
orderId: maker.id,
pairId: maker.pairId,
quantity: portion.quantity,
peerPubKey: maker.peerPubKey,
};
swapFailures.push(swapFailure);
onUpdate && onUpdate({ type: PlaceOrderEventType.SwapFailure, payload: swapFailure });
await retryFailedSwap(portion.quantity);
} else {
this.logger.error(`${failMsg} due to unexpected error, will repeat matching routine for failed quantity`, err);
failureReason = SwapFailureReason.UnknownError;
// treat this as a critical error and abort matching, we only expect SwapFailureReasons to be thrown in the try block above
this.logger.error(`${failMsg} due to unexpected error`, err);
throw err;
}

const swapFailure: SwapFailure = {
failureReason,
orderId: maker.id,
pairId: maker.pairId,
quantity: portion.quantity,
peerPubKey: maker.peerPubKey,
};
swapFailures.push(swapFailure);
onUpdate && onUpdate({ type: PlaceOrderEventType.SwapFailure, payload: swapFailure });
await retryFailedSwap(portion.quantity);
}
}
};
Expand Down

0 comments on commit cfe51ee

Please sign in to comment.