Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
[FIX] Removing GET /notifications, handle exceptions in getTransaction
Browse files Browse the repository at this point in the history
- getTransaction was not handling exceptions thrown by the validation
  calls

- Example:

```
2015-04-13T22:54:51.183Z - error: uncaughtException: Parameter missing:
paymentIdentifier
{ date: 'Mon Apr 13 2015 22:54:51 GMT+0000 (UTC)',
```
  • Loading branch information
Alan Cohen committed Apr 13, 2015
1 parent 8cb8008 commit 1b03165
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 8 additions & 2 deletions api/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,13 @@ function attachPreviousAndNextTransactionIdentifiers(api,
* @param {Notification} notification
*/
function getNotificationHelper(api, account, identifier, topCallback) {
validate.address(account);

function getTransaction(callback) {
transactions.getTransaction(api, account, identifier, {}, callback);
try {
transactions.getTransaction(api, account, identifier, {}, callback);
} catch(err) {
callback(err);
}
}

function checkLedger(baseTransaction, callback) {
Expand Down Expand Up @@ -237,6 +240,9 @@ function getNotificationHelper(api, account, identifier, topCallback) {
* @param {Hex-encoded String|ResourceId} req.params.identifier
*/
function getNotification(account, identifier, urlBase, callback) {
validate.address(account);
validate.paymentIdentifier(identifier);

getNotificationHelper(this, account, identifier,
function(error, notification) {
if (error) {
Expand Down
15 changes: 10 additions & 5 deletions api/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,18 @@ function setTransactionBitFlags(transaction, options) {
* @param {Transaction} transaction
*/
function getTransaction(api, account, identifier, requestOptions, callback) {
assert(requestOptions);
assert.strictEqual(typeof requestOptions, 'object');

try {
assert.strictEqual(typeof requestOptions, 'object');

validate.address(account, true);
validate.paymentIdentifier(identifier);
validate.ledger(requestOptions.ledger, true);
} catch(err) {
return callback(err);
}

var options = { };
validate.address(account, true);
validate.paymentIdentifier(identifier);
validate.ledger(requestOptions.ledger, true);

if (validator.isValid(identifier, 'Hash256')) {
options.hash = identifier;
Expand Down
1 change: 0 additions & 1 deletion server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ module.exports = {
'/accounts/:account/orders': makeMiddleware(getOrders),
'/accounts/:account/order_book/:base/:counter': makeMiddleware(getOrderBook),
'/accounts/:account/orders/:identifier': makeMiddleware(getOrder),
'/accounts/:account/notifications': makeMiddleware(getNotification),
'/accounts/:account/notifications/:identifier': makeMiddleware(getNotification),
'/accounts/:account/balances': makeMiddleware(getBalances),
'/accounts/:account/settings': makeMiddleware(getSettings),
Expand Down

0 comments on commit 1b03165

Please sign in to comment.