|
|
@@ -76,10 +76,16 @@ app.post("/buy", async (req, res) => {
|
|
|
throw Error(JSON.stringify({ error: { name: "Error, request body has no \"user\" property!" } }));
|
|
|
}
|
|
|
|
|
|
+ if (!req.body.privateKey) {
|
|
|
+ res.status(400);
|
|
|
+ throw Error(JSON.stringify({ error: { name: "Error, user must provide \"privateKey\" to sign transaction!" } }));
|
|
|
+ }
|
|
|
+
|
|
|
let price = getPrice(req.body.extent);
|
|
|
|
|
|
let irohaResponse = await forwardBuyRequest(
|
|
|
{
|
|
|
+ privateKey: req.body.privateKey,
|
|
|
transfers: [
|
|
|
{
|
|
|
asset: IROHA_ASSET + "#" + IROHA_DOMAIN,
|
|
|
@@ -96,8 +102,9 @@ app.post("/buy", async (req, res) => {
|
|
|
|
|
|
res.status(irohaResponse.status);
|
|
|
|
|
|
- if(!irohaResponse.ok){
|
|
|
- res.send(irohaResponse);
|
|
|
+ if (!irohaResponse.ok) {
|
|
|
+ res.send(await irohaResponse.json());
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
let irohaResponseJson = await irohaResponse.json();
|
|
|
@@ -143,11 +150,7 @@ function getPrice(extent) {
|
|
|
|
|
|
function error(err, req, res, next) { //TODO: add custom Exception class
|
|
|
console.log(err);
|
|
|
-
|
|
|
- if (!res.status) {
|
|
|
res.status(500);
|
|
|
- }
|
|
|
-
|
|
|
res.send(err.message);
|
|
|
}
|
|
|
|