forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbalance.ts
57 lines (50 loc) · 1.74 KB
/
balance.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright 2020-2021 Hyperledger Cactus Contributors
* SPDX-License-Identifier: Apache-2.0
*
* balance.ts
*/
import { Router, NextFunction, Request, Response } from "express";
import { RIFUtil } from "../../packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/util/RIFUtil";
import { ConfigUtil } from "../../packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/util/ConfigUtil";
import {
RIFError,
BadRequestError,
InternalServerError,
} from "../../packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/RIFError";
import { BalanceManagement } from "./BalanceManagement";
const fs = require("fs");
const path = require("path");
const config: any = ConfigUtil.getConfig();
import { getLogger } from "log4js";
const moduleName = "balance";
const logger = getLogger(`${moduleName}`);
logger.level = config.logLevel;
const router: Router = Router();
const balanceManagement: BalanceManagement = new BalanceManagement();
/* GET balance. */
router.get("/:account", (req: Request, res: Response, next: NextFunction) => {
try {
balanceManagement
.getBalance(req.params.account)
.then((result) => {
logger.debug(`#####[sample/balance.ts]`);
logger.debug("result(getBalance) = " + JSON.stringify(result));
res.status(200).json(result);
})
.catch((err) => {
logger.error(err);
});
} catch (err) {
logger.error(`##err name: ${err.constructor.name}`);
if (err instanceof RIFError) {
logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`);
res.status(err.statusCode);
res.send(err.message);
return;
}
logger.error(`##err in balance: ${err}`);
next(err);
}
});
export default router;