Commit b21c4fec10ce785df9c883db22c69406e8f73990
1 parent
ff8221ba96
Exists in
master
USSD: Return on error
Showing 1 changed file with 2 additions and 0 deletions Inline Diff
lib/http-command-server/router-ussd.js
1 | 'use strict'; | 1 | 'use strict'; |
2 | 2 | ||
3 | const express = require('express'); | 3 | const express = require('express'); |
4 | 4 | ||
5 | const modem = require('../modem'); | 5 | const modem = require('../modem'); |
6 | 6 | ||
7 | const router = express.Router(); | 7 | const router = express.Router(); |
8 | module.exports = router; | 8 | module.exports = router; |
9 | 9 | ||
10 | 10 | ||
11 | async function handlerIndex(req, res) { | 11 | async function handlerIndex(req, res) { |
12 | if (!req.query || !req.query.code || typeof req.query.code !== 'string') { | 12 | if (!req.query || !req.query.code || typeof req.query.code !== 'string') { |
13 | res.json({ | 13 | res.json({ |
14 | status: 'NOT-OK', | 14 | status: 'NOT-OK', |
15 | error: 'INVALID-PARAMETER', | 15 | error: 'INVALID-PARAMETER', |
16 | message: 'Undefined parameter: code', | 16 | message: 'Undefined parameter: code', |
17 | }); | 17 | }); |
18 | |||
19 | return; | ||
18 | } | 20 | } |
19 | 21 | ||
20 | const reply = await modem.executeUSSD(req.query.code); | 22 | const reply = await modem.executeUSSD(req.query.code); |
21 | res.json({ | 23 | res.json({ |
22 | status: 'OK', | 24 | status: 'OK', |
23 | error: false, | 25 | error: false, |
24 | code: req.query.code, | 26 | code: req.query.code, |
25 | result: reply, | 27 | result: reply, |
26 | message: 'USSD executed', | 28 | message: 'USSD executed', |
27 | }); | 29 | }); |
28 | } | 30 | } |
29 | 31 | ||
30 | router.get('/', handlerIndex); | 32 | router.get('/', handlerIndex); |
31 | 33 |