Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/check for 404 #262

Merged
merged 10 commits into from
Mar 16, 2020
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