mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
fix unhandled exception (#473)
* handle error and return 400 * Update accounts.js * Update accounts.js * new test passing
This commit is contained in:
@@ -286,7 +286,11 @@ const hasAccountPermissions = async(req, res, next) => {
|
|||||||
message: 'insufficient privileges'
|
message: 'insufficient privileges'
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
// return 400 on errors
|
||||||
|
res.status(400).json({
|
||||||
|
status: 'fail',
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -266,6 +266,19 @@ test('account tests', async(t) => {
|
|||||||
t.ok(err.statusCode === 400, 'returns 400 bad request if account sid param is not a valid uuid');
|
t.ok(err.statusCode === 400, 'returns 400 bad request if account sid param is not a valid uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* try to fetch Alerts with an invalid account SID */
|
||||||
|
try {
|
||||||
|
result = await request.get(`/Accounts/INVALID/Alerts?page=1&count=1`, {
|
||||||
|
auth: {bearer: accountLevelToken},
|
||||||
|
resolveWithFullResponse: true,
|
||||||
|
json: true
|
||||||
|
});
|
||||||
|
t.fail('Expected request to fail with invalid account SID');
|
||||||
|
console.log(result)
|
||||||
|
} catch (err) {
|
||||||
|
t.ok(err.statusCode === 400, 'returns 400 bad request if account sid param is not a valid uuid');
|
||||||
|
}
|
||||||
|
|
||||||
/* query all limits for an account */
|
/* query all limits for an account */
|
||||||
result = await request.get(`/Accounts/${sid}/Limits`, {
|
result = await request.get(`/Accounts/${sid}/Limits`, {
|
||||||
auth: authAdmin,
|
auth: authAdmin,
|
||||||
@@ -337,6 +350,7 @@ test('account tests', async(t) => {
|
|||||||
await deleteObjectBySid(request, '/VoipCarriers', voip_carrier_sid);
|
await deleteObjectBySid(request, '/VoipCarriers', voip_carrier_sid);
|
||||||
await deleteObjectBySid(request, '/ServiceProviders', service_provider_sid);
|
await deleteObjectBySid(request, '/ServiceProviders', service_provider_sid);
|
||||||
//t.end();
|
//t.end();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user