Skip to content

Commit

Permalink
Feature/check for 404 (#262)
Browse files Browse the repository at this point in the history
* Added additional check of the returned status code being 404 in case there is a communication error with the target oracle endpoint.

* Bump to 9.3.2

* Added comments to clarify the reason of this change.

* Fixed vulnerabilities with `npm audit fix`

* Fixed the remaining vulnerabilities with `npm audit fix`

* Changed the returned error code on the edge case of `DESTINATION_COMMUNICATION_ERROR` && `NOTFOUND.CODE` to be `DESTINATION_FSP_ERROR` instead of `PARTY_NOT_FOUND`

* Removed accidentally committed file.

* Bumped to 9.4.1
  • Loading branch information
Vassilis Barzokas authored Mar 16, 2020
1 parent d19c515 commit 5418b67
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 20 deletions.
49 changes: 47 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "account-lookup-service",
"description": "Account Lookup Service is used to validate Party and Participant lookups",
"version": "9.4.0",
"version": "9.4.1",
"license": "Apache-2.0",
"author": "ModusBox",
"contributors": [
Expand Down
14 changes: 9 additions & 5 deletions src/models/oracle/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ exports.oracleRequest = async (headers, method, params = {}, query = {}, payload
Logger.error(err)
// If the error was a 400 from the Oracle, we'll modify the error to generate a response to the
// initiator of the request.
// Added error 404 to cover a special case of the Mowali implementation
// which uses mojaloop/als-oracle-pathfinder and currently returns 404.
if (
err.name === 'FSPIOPError' &&
err.apiErrorCode.code === ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_COMMUNICATION_ERROR.code &&
err.extensions.some(ext => (ext.key === 'status' && (ext.value === Enums.Http.ReturnCodes.BADREQUEST.CODE || ext.value === Enums.Http.ReturnCodes.NOTFOUND.CODE)))
err.apiErrorCode.code === ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_COMMUNICATION_ERROR.code
) {
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PARTY_NOT_FOUND)
if (err.extensions.some(ext => (ext.key === 'status' && ext.value === Enums.Http.ReturnCodes.BADREQUEST.CODE))) {
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PARTY_NOT_FOUND)
// Added error 404 to cover a special case of the Mowali implementation
// which uses mojaloop/als-oracle-pathfinder and currently returns 404
// and in which case the Mowali implementation expects back `DESTINATION_FSP_ERROR`.
} else if (err.extensions.some(ext => (ext.key === 'status' && ext.value === Enums.Http.ReturnCodes.NOTFOUND.CODE))) {
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR)
}
}
throw ErrorHandler.Factory.reformatFSPIOPError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/handlers/participants/{Type}/{ID}.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('/participants/{Type}/{ID}', () => {
participants.getParticipantsByTypeAndID.restore()
})

it('getParticipantsByTypeAndID sends an async 3200 for invalid party id on response with status 400', async () => {
it('getParticipantsByTypeAndID sends an async 3204 for invalid party id on response with status 400', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/participants/{Type}/{ID}', 'get')
const options = {
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('/participants/{Type}/{ID}', () => {

// Added error 404 to cover a special case of the Mowali implementation
// which uses mojaloop/als-oracle-pathfinder and currently returns 404.
it('getParticipantsByTypeAndID sends an async 3200 for invalid party id on response with status 404', async () => {
it('getParticipantsByTypeAndID sends an async 3201 for invalid party id on response with status 404', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/participants/{Type}/{ID}', 'get')
const options = {
Expand All @@ -139,7 +139,7 @@ describe('/participants/{Type}/{ID}', () => {
const errorCallStub = stubs[0]

// Assert
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3204')
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3201')
expect(errorCallStub.args[0][1]).toBe(Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_PUT_ERROR)
expect(response.statusCode).toBe(202)
stubs.forEach(s => s.restore())
Expand Down
6 changes: 3 additions & 3 deletions test/unit/handlers/participants/{Type}/{ID}/{SubId}.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('/participants/{Type}/{ID}/{SubId}', () => {
participants.getParticipantsByTypeAndID.restore()
})

it('getParticipantsByTypeAndID sends an async 3200 for invalid party id on response with status 400', async () => {
it('getParticipantsByTypeAndID sends an async 3204 for invalid party id on response with status 400', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/participants/{Type}/{ID}/{SubId}', 'get')
const options = {
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('/participants/{Type}/{ID}/{SubId}', () => {

// Added error 404 to cover a special case of the Mowali implementation
// which uses mojaloop/als-oracle-pathfinder and currently returns 404.
it('getParticipantsByTypeAndID sends an async 3200 for invalid party id on response with status 404', async () => {
it('getParticipantsByTypeAndID sends an async 3201 for invalid party id on response with status 404', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/participants/{Type}/{ID}/{SubId}', 'get')
const options = {
Expand All @@ -135,7 +135,7 @@ describe('/participants/{Type}/{ID}/{SubId}', () => {
const errorCallStub = stubs[0]

// Assert
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3204')
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3201')
expect(errorCallStub.args[0][1]).toBe(Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_SUB_ID_PUT_ERROR)
expect(response.statusCode).toBe(202)
stubs.forEach(s => s.restore())
Expand Down
6 changes: 3 additions & 3 deletions test/unit/handlers/parties/{Type}/{ID}.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('/parties', () => {
parties.getPartiesByTypeAndID.restore()
})

it('getPartiesByTypeAndID endpoint sends async 3200 to /error for invalid party ID on response with status 400', async () => {
it('getPartiesByTypeAndID endpoint sends async 3204 to /error for invalid party ID on response with status 400', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/parties/{Type}/{ID}', 'get')
const options = {
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('/parties', () => {

// Added error 404 to cover a special case of the Mowali implementation
// which uses mojaloop/als-oracle-pathfinder and currently returns 404.
it('getPartiesByTypeAndID endpoint sends async 3200 to /error for invalid party ID on response with status 404', async () => {
it('getPartiesByTypeAndID endpoint sends async 3201 to /error for invalid party ID on response with status 404', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/parties/{Type}/{ID}', 'get')
const options = {
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('/parties', () => {

// Assert
const errorCallStub = stubs[0]
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3204')
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3201')
expect(errorCallStub.args[0][1]).toBe(Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR)
expect(response.statusCode).toBe(202)
stubs.forEach(s => s.restore())
Expand Down
6 changes: 3 additions & 3 deletions test/unit/handlers/parties/{Type}/{ID}/{SubId}.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('/parties/{Type}/{ID}/{SubId}', () => {
parties.getPartiesByTypeAndID.restore()
})

it('getPartiesByTypeAndID endpoint sends async 3200 to /error for invalid party ID on response with status 400', async () => {
it('getPartiesByTypeAndID endpoint sends async 3204 to /error for invalid party ID on response with status 400', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/parties/{Type}/{ID}/{SubId}', 'get')
const options = {
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('/parties/{Type}/{ID}/{SubId}', () => {

// Added error 404 to cover a special case of the Mowali implementation
// which uses mojaloop/als-oracle-pathfinder and currently returns 404.
it('getPartiesByTypeAndID endpoint sends async 3200 to /error for invalid party ID with status 404', async () => {
it('getPartiesByTypeAndID endpoint sends async 3201 to /error for invalid party ID with status 404', async () => {
// Arrange
const mock = await Helper.generateMockRequest('/parties/{Type}/{ID}/{SubId}', 'get')
const options = {
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('/parties/{Type}/{ID}/{SubId}', () => {

// Assert
const errorCallStub = stubs[0]
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3204')
expect(errorCallStub.args[0][2].errorInformation.errorCode).toBe('3201')
expect(errorCallStub.args[0][1]).toBe(Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_SUB_ID_PUT_ERROR)
expect(response.statusCode).toBe(202)
stubs.forEach(s => s.restore())
Expand Down

0 comments on commit 5418b67

Please sign in to comment.