Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Get empty array instead of 404 when not found in p360
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgtho committed Oct 26, 2021
1 parent 0541276 commit 65db168
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/repack-result.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { logger } = require('@vtfk/logger')
const hasData = require('./has-data')
const HTTPError = require('./http-error')

const unwantedProperties = [
'ErrorDetails',
Expand Down Expand Up @@ -53,8 +52,7 @@ module.exports = (result = {}, options) => {
}

if (output.length === 1 && !hasData(output[0])) {
logger('error', ['repack-result', 404, 'Not found'])
throw new HTTPError(404, 'Not found')
return []
}

return output
Expand Down
18 changes: 18 additions & 0 deletions test/repack-result.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ const resultCreateCaseWithErrorMessage = repackResult({
TotalPageCount: 1
})

const resultPrivatePersonWithEmptyResponse = repackResult({
PrivatePersons: [],
TotalPageCount: 0,
TotalCount: 0,
Successful: true,
ErrorMessage: null,
ErrorDetails: null
})

test('PrivatePerson result is Array', () => {
expect(Array.isArray(resultPrivatePerson)).toBe(true)
})
Expand All @@ -199,6 +208,15 @@ test('PrivatePerson results one item has a "Recno" property', () => {
expect(resultPrivatePerson[0].Recno).toBe(123456)
})

test('PrivatePerson with empty response is array', () => {
expect(Array.isArray(resultPrivatePersonWithEmptyResponse)).toBe(true)
})

test('PrivatePerson with empty response is empty array', () => {
console.log(resultPrivatePersonWithEmptyResponse)
expect(resultPrivatePersonWithEmptyResponse.length).toBe(0)
})

test('CreateCase result is Array', () => {
expect(Array.isArray(resultCreateCase)).toBe(true)
})
Expand Down

0 comments on commit 65db168

Please sign in to comment.