diff --git a/app.js b/app.js index c770e4f1..a170261d 100644 --- a/app.js +++ b/app.js @@ -87,13 +87,17 @@ app.use(function(req, res, next) { // error handler app.use(function(err, req, res, next) { + // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page res.status(err.status || 500); - res.render('error'); + res.json({ + status: 500, + message: err.message + }); }); module.exports = app; diff --git a/public/bitbox-rest-v1.json b/public/bitbox-rest-v1.json index 963a4818..21301301 100644 --- a/public/bitbox-rest-v1.json +++ b/public/bitbox-rest-v1.json @@ -122,10 +122,16 @@ ], "responses": { "200": { - "description": "successful response" + "description": "successful response", + "schema": { + "$ref": "#/definitions/AddressDetails" + } }, "400": { - "description": "Invalid tag value" + "schema": { + "status": 500, + "message": "Received an invalid Bitcoin Cash address as input." + } } } } @@ -155,10 +161,16 @@ ], "responses": { "200": { - "description": "successful response" + "description": "successful response", + "schema": { + "$ref": "#/definitions/AddressUtxo" + } }, "400": { - "description": "Invalid tag value" + "schema": { + "status": 500, + "message": "Received an invalid Bitcoin Cash address as input." + } } } } @@ -1404,5 +1416,102 @@ } } } + }, + "definitions": { + "AddressDetails": { + "type": "object", + "properties": { + "balance": { + "type": "number", + "format": "float" + }, + "balanceSat": { + "type": "number", + "format": "float" + }, + "totalReceived": { + "type": "number", + "format": "float" + }, + "totalReceivedSat": { + "type": "number", + "format": "float" + }, + "totalSent": { + "type": "number", + "format": "float" + }, + "totalSentSat": { + "type": "number", + "format": "float" + }, + "unconfirmedBalance": { + "type": "number", + "format": "float" + }, + "unconfirmedBalanceSat": { + "type": "number", + "format": "float" + }, + "unconfirmedTxApperances": { + "type": "number", + "format": "float" + }, + "txApperances": { + "type": "number" + }, + "transactions": { + "type": "array", + "items": { + "type": "string" + } + }, + "legacyAddress": { + "type": "string" + }, + "cashAddress": { + "type": "string" + } + } + }, + "AddressUtxo": { + "type": "array", + "items": { + "$ref": "#/definitions/Utxo" + } + }, + "Utxo": { + "type": "object", + "properties": { + "txid": { + "type": "string" + }, + "vout": { + "type": "number" + }, + "scriptPubKey": { + "type": "string" + }, + "amount": { + "type": "number", + "format": "float" + }, + "satoshis": { + "type": "number" + }, + "height": { + "type": "number" + }, + "confirmations": { + "type": "number" + }, + "legacyAddress": { + "type": "string" + }, + "cashAddress": { + "type": "string" + } + } + } } } diff --git a/routes/address.js b/routes/address.js index f2e83c40..7fefb7cd 100644 --- a/routes/address.js +++ b/routes/address.js @@ -36,7 +36,8 @@ router.get('/details/:address', function(req, res, next) { result.data.legacyAddress = BITBOX.Address.toLegacyAddress(req.params.address); result.data.cashAddress = BITBOX.Address.toCashAddress(req.params.address); res.json(result.data); - }, (err) => { console.log(err); + }, (err) => { + console.log(err); }); } });