diff options
author | Fabio Berger <me@fabioberger.com> | 2018-05-16 20:59:10 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-05-16 20:59:10 +0800 |
commit | 839db68571037f6fff8273aaade6ea0bd14ea8a5 (patch) | |
tree | 302b3164f01bc5363bf07841a42fa30b3842169e /packages/testnet-faucets/src/ts | |
parent | fec6ac3ff0c4781cea0b3f42e287aee2b8aa2a79 (diff) | |
download | dexon-0x-contracts-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar.gz dexon-0x-contracts-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar.zst dexon-0x-contracts-839db68571037f6fff8273aaade6ea0bd14ea8a5.zip |
Fix TSLint rules
Diffstat (limited to 'packages/testnet-faucets/src/ts')
-rw-r--r-- | packages/testnet-faucets/src/ts/constants.ts | 5 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/handler.ts | 11 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/parameter_transformer.ts | 5 | ||||
-rw-r--r-- | packages/testnet-faucets/src/ts/server.ts | 6 |
4 files changed, 18 insertions, 9 deletions
diff --git a/packages/testnet-faucets/src/ts/constants.ts b/packages/testnet-faucets/src/ts/constants.ts new file mode 100644 index 000000000..c6370e3f6 --- /dev/null +++ b/packages/testnet-faucets/src/ts/constants.ts @@ -0,0 +1,5 @@ +export const constants = { + SUCCESS_STATUS: 200, + SERVICE_UNAVAILABLE_STATUS: 503, + BAD_REQUEST_STATUS: 400, +}; diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index 3858b5339..d5f0dc2f9 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -15,6 +15,7 @@ import ProviderEngine = require('web3-provider-engine'); import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { configs } from './configs'; +import { constants } from './constants'; import { DispatchQueue } from './dispatch_queue'; import { dispenseAssetTasks } from './dispense_asset_tasks'; import { rpcUrls } from './rpc_urls'; @@ -80,7 +81,7 @@ export class Handler { }; }); const payload = JSON.stringify(queueInfo); - res.status(200).send(payload); + res.status(constants.SUCCESS_STATUS).send(payload); } public dispenseEther(req: express.Request, res: express.Response): void { this._dispenseAsset(req, res, RequestedAssetType.ETH); @@ -120,11 +121,11 @@ export class Handler { } const didAddToQueue = networkConfig.dispatchQueue.add(dispenserTask); if (!didAddToQueue) { - res.status(503).send('QUEUE_IS_FULL'); + res.status(constants.SERVICE_UNAVAILABLE_STATUS).send('QUEUE_IS_FULL'); return; } logUtils.log(`Added ${recipient} to queue: ${requestedAssetType} networkId: ${networkId}`); - res.status(200).end(); + res.status(constants.SUCCESS_STATUS).end(); } private async _dispenseOrderAsync( req: express.Request, @@ -133,7 +134,7 @@ export class Handler { ): Promise<void> { const networkConfig = _.get(this._networkConfigByNetworkId, req.params.networkId); if (_.isUndefined(networkConfig)) { - res.status(400).send('UNSUPPORTED_NETWORK_ID'); + res.status(constants.BAD_REQUEST_STATUS).send('UNSUPPORTED_NETWORK_ID'); return; } const zeroEx = networkConfig.zeroEx; @@ -173,6 +174,6 @@ export class Handler { const signedOrderHash = ZeroEx.getOrderHashHex(signedOrder); const payload = JSON.stringify(signedOrder); logUtils.log(`Dispensed signed order: ${payload}`); - res.status(200).send(payload); + res.status(constants.SUCCESS_STATUS).send(payload); } } diff --git a/packages/testnet-faucets/src/ts/parameter_transformer.ts b/packages/testnet-faucets/src/ts/parameter_transformer.ts index 58bf154dc..b9929a0d9 100644 --- a/packages/testnet-faucets/src/ts/parameter_transformer.ts +++ b/packages/testnet-faucets/src/ts/parameter_transformer.ts @@ -3,6 +3,7 @@ import { NextFunction, Request, Response } from 'express'; import * as _ from 'lodash'; import { configs } from './configs'; +import { constants } from './constants'; import { rpcUrls } from './rpc_urls'; const DEFAULT_NETWORK_ID = 42; // kovan @@ -11,7 +12,7 @@ export const parameterTransformer = { transform(req: Request, res: Response, next: NextFunction): void { const recipientAddress = req.params.recipient; if (_.isUndefined(recipientAddress) || !addressUtils.isAddress(recipientAddress)) { - res.status(400).send('INVALID_RECIPIENT_ADDRESS'); + res.status(constants.BAD_REQUEST_STATUS).send('INVALID_RECIPIENT_ADDRESS'); return; } const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); @@ -19,7 +20,7 @@ export const parameterTransformer = { const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID); const rpcUrlIfExists = _.get(rpcUrls, networkId); if (_.isUndefined(rpcUrlIfExists)) { - res.status(400).send('UNSUPPORTED_NETWORK_ID'); + res.status(constants.BAD_REQUEST_STATUS).send('UNSUPPORTED_NETWORK_ID'); return; } req.params.networkId = networkId; diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts index 198a5fdc9..55c1d55d8 100644 --- a/packages/testnet-faucets/src/ts/server.ts +++ b/packages/testnet-faucets/src/ts/server.ts @@ -1,6 +1,7 @@ import * as bodyParser from 'body-parser'; import * as express from 'express'; +import { constants } from './constants'; import { errorReporter } from './error_reporter'; import { Handler } from './handler'; import { parameterTransformer } from './parameter_transformer'; @@ -18,7 +19,7 @@ app.use((req, res, next) => { const handler = new Handler(); app.get('/ping', (req: express.Request, res: express.Response) => { - res.status(200).send('pong'); + res.status(constants.SUCCESS_STATUS).send('pong'); }); app.get('/info', handler.getQueueInfo.bind(handler)); app.get('/ether/:recipient', parameterTransformer.transform, handler.dispenseEther.bind(handler)); @@ -28,5 +29,6 @@ app.get('/order/zrx/:recipient', parameterTransformer.transform, handler.dispens // Log to rollbar any errors unhandled by handlers app.use(errorReporter.errorHandler()); -const port = process.env.PORT || 3000; +const DEFAULT_PORT = 3000; +const port = process.env.PORT || DEFAULT_PORT; app.listen(port); |