Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

Commit

Permalink
feat: improve swap not found error message (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Mar 11, 2019
1 parent c117de5 commit fdfeeaf
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/BaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter } from 'events';
import { ClientStatus } from './consts/ClientStatus';
import { ClientStatus } from './consts/Enums';

class BaseClient extends EventEmitter {
protected status = ClientStatus.Disconnected;
Expand Down
12 changes: 6 additions & 6 deletions lib/api/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Controller {
if (response) {
this.successResponse(res, response);
} else {
this.successResponse(res, { message: `Could not find swap with id: ${id}` });
this.errorResponse(res, `could not find swap with id: ${id}`, 404);
}
} catch (error) {
this.errorResponse(res, error);
Expand Down Expand Up @@ -174,11 +174,11 @@ class Controller {
return response;
}

private errorResponse = (res: Response, error: any) => {
private errorResponse = (res: Response, error: any, statusCode = 400) => {
if (typeof error === 'string') {
this.invalidArgumentsResponse(res, error);
this.invalidArgumentsResponse(res, statusCode, error);
} else {
this.invalidArgumentsResponse(res, error.message);
this.invalidArgumentsResponse(res, statusCode, error.message);
}
}

Expand All @@ -192,11 +192,11 @@ class Controller {
res.status(201).json(data);
}

private invalidArgumentsResponse = (res: Response, error: string) => {
private invalidArgumentsResponse = (res: Response, statusCode: number, error: string) => {
this.logger.warn(`Request failed: ${error}`);

this.setContentTypeJson(res);
res.status(400).json({ error });
res.status(statusCode).json({ error });
}

private setContentTypeJson = (res: Response) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/boltz/BoltzClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Errors from './Errors';
import Logger from '../Logger';
import { stringify } from '../Utils';
import BaseClient from '../BaseClient';
import { ClientStatus } from '../consts/Enums';
import * as boltzrpc from '../proto/boltzrpc_pb';
import { ClientStatus } from '../consts/ClientStatus';
import { BoltzClient as GrpcClient } from '../proto/boltzrpc_grpc_pb';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/boltz/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Error } from '../consts/Types';
import { ErrorCodePrefix } from '../consts/ErrorCodePrefix';
import { concatErrorCode } from '../Utils';
import { ErrorCodePrefix } from '../consts/Enums';

export default {
COULD_NOT_FIND_FILES: (file: string): Error => ({
Expand Down
4 changes: 0 additions & 4 deletions lib/consts/ClientStatus.ts

This file was deleted.

21 changes: 21 additions & 0 deletions lib/consts/Enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export enum ClientStatus {
Connected,
Disconnected,
}

export enum ErrorCodePrefix {
General = 0,
Api = 1,
Service = 2,
BoltzClient = 3,
RateProvider = 4,
}

export enum SwapUpdateEvent {
InvoicePaid = 'invoice.paid',
InvoiceSettled = 'invoice.settled',
InvoiceFailedToPay = 'invoice.failedToPay',

TransactionRefunded = 'transaction.refunded',
TransactionConfirmed = 'transaction.confirmed',
}
7 changes: 0 additions & 7 deletions lib/consts/ErrorCodePrefix.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/rates/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Error } from '../consts/Types';
import { ErrorCodePrefix } from '../consts/ErrorCodePrefix';
import { concatErrorCode } from '../Utils';
import { ErrorCodePrefix } from '../consts/Enums';

export default {
COULD_NOT_GET_RATE: (error: string): Error => ({
Expand Down
2 changes: 1 addition & 1 deletion lib/service/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Error } from '../consts/Types';
import { ErrorCodePrefix } from '../consts/ErrorCodePrefix';
import { concatErrorCode } from '../Utils';
import { ErrorCodePrefix } from '../consts/Enums';

export default {
CURRENCY_NOT_SUPPORTED_BY_BACKEND: (currency: string): Error => ({
Expand Down
11 changes: 1 addition & 10 deletions lib/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Database from '../db/Database';
import PairRepository from './PairRepository';
import BoltzClient from '../boltz/BoltzClient';
import RateProvider from '../rates/RateProvider';
import { SwapUpdateEvent } from '../consts/Enums';
import { encodeBip21 } from './PaymentRequestUtils';
import { PairInstance, PairFactory } from '../consts/Database';
import { CurrencyConfig } from '../notifications/NotificationProvider';
Expand Down Expand Up @@ -36,16 +37,6 @@ type PendingReverseSwap = {
transactionHash: string;
};

// Enums and types related to swap updates
enum SwapUpdateEvent {
InvoicePaid = 'invoice.paid',
InvoiceSettled = 'invoice.settled',
InvoiceFailedToPay = 'invoice.failedToPay',

TransactionRefunded = 'transaction.refunded',
TransactionConfirmed = 'transaction.confirmed',
}

type SwapUpdate = {
event: SwapUpdateEvent,

Expand Down

0 comments on commit fdfeeaf

Please sign in to comment.