Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

fix: handle null response from /messages #126

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/services/mailchain/mailchain.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ describe('MailchainService', () => {
expect(mailchainService.filterMessages(messages, {status: "error", readState: true, headersTo: address2})).toEqual([ messages[1] ])
expect(mailchainService.filterMessages(messages, {status: "error", readState: false, headersTo: address2})).toEqual([ messages[3] ])
})
it('should handle messages returned as null', () => {
expect(mailchainService.filterMessages(null, { status: "ok" })).toEqual([])
expect(mailchainService.filterMessages(null, { readState: true })).toEqual([])
expect(mailchainService.filterMessages(null, { headersTo: address1 })).toEqual([])
})
})

describe('validateEnsName', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/app/services/mailchain/mailchain.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ export class MailchainService {
let readState = options.readState
let headersTo = options.headersTo
let output = msgsArray
if (status != undefined ) {
output = output.filter(msg => msg.status === status)
if (status != undefined) {
output = output == null ? [] : output.filter(msg => msg.status === status)
}
if (readState != undefined) {
output = output.filter(msg => msg.read === readState)
output = output == null ? [] : output.filter(msg => msg.read === readState)
}
if (headersTo != undefined) {
output = output.filter(msg =>
output = output == null ? [] : output.filter(msg =>
this.parseAddressFromMailchain(msg["headers"]["to"]) == headersTo
)
}
Expand Down