fix: phin handle 400 empty body

phin doesn't throw on 400 and instead passes empty body to tg
This commit is contained in:
Mohamed Sohail 2022-01-18 19:39:15 +03:00
parent 30b60899d5
commit 43b7800ed6
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
2 changed files with 5 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "ussd-tg-proxy",
"version": "0.3.0",
"version": "0.3.1",
"description": "ussd-tg-proxy",
"main": "src/index.js",
"repository": "https://git.grassecon.net/grassrootseconomics/ussd-tg-proxy.git",

View File

@ -21,7 +21,10 @@ async function proxy(sessionId, phone, input = "") {
try {
const { body } = await phin(requestOptions);
log.debug({ body: body }, "response body");
return body;
if (body.length > 1) {
return body;
}
throw new Error("empty body");
} catch (error) {
log.error(error);
return "ERR Something went wrong, try again later.";