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

Improve reissuing error logging #320

Merged
merged 4 commits into from
Jul 26, 2023
Merged
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
14 changes: 11 additions & 3 deletions app/services/billing/supplementary/reissue-invoice.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function _pauseUntilNotPending (billingBatchExternalId) {
if (!result.succeeded) {
const error = new ExpandedError(
'Charging Module reissue request failed',
{ billingBatchExternalId }
{ billingBatchExternalId, responseBody: result.response.body }
)

throw error
Expand Down Expand Up @@ -280,7 +280,11 @@ async function _sendReissueRequest (billingBatchExternalId, invoiceExternalId) {
if (!result.succeeded) {
const error = new ExpandedError(
'Charging Module reissue request failed',
{ billingBatchExternalId, invoiceExternalId }
{
billingBatchExternalId,
invoiceExternalId,
responseBody: result.response.body
}
)

throw error
Expand All @@ -298,7 +302,11 @@ async function _sendViewInvoiceRequest (billingBatch, reissueInvoiceId) {
if (!result.succeeded) {
const error = new ExpandedError(
'Charging Module view invoice request failed',
{ billingBatchExternalId: billingBatch.externalId, reissueInvoiceExternalId: reissueInvoiceId }
{
billingBatchExternalId: billingBatch.externalId,
reissueInvoiceExternalId: reissueInvoiceId,
responseBody: result.response.body
}
)

throw error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,16 @@ describe('Reissue invoice service', () => {
describe('when sending the reissue request', () => {
beforeEach(() => {
ChargingModuleReissueInvoiceService.go.restore()
Sinon.stub(ChargingModuleReissueInvoiceService, 'go').resolves({ succeeded: false })
Sinon.stub(ChargingModuleReissueInvoiceService, 'go').resolves({
succeeded: false,
response: {
body: {
error: 'Conflict',
message: 'Invoice 2274cd48-2a61-4b73-a9c0-bc5696c5218d has already been rebilled.',
statusCode: 409
}
}
})
})

it('throws an error', async () => {
Expand All @@ -267,12 +276,29 @@ describe('Reissue invoice service', () => {
expect(errorResult.billingBatchExternalId).to.equal(reissueBillingBatch.externalId)
expect(errorResult.invoiceExternalId).to.equal(sourceInvoice.externalId)
})

it('includes the Charging Module response body', async () => {
const errorResult = await expect(ReissueInvoiceService.go(sourceInvoice, reissueBillingBatch)).to.reject()

expect(errorResult.responseBody.error).to.equal('Conflict')
expect(errorResult.responseBody.message).to.equal('Invoice 2274cd48-2a61-4b73-a9c0-bc5696c5218d has already been rebilled.')
expect(errorResult.responseBody.statusCode).to.equal(409)
})
})

describe('when viewing an invoice', () => {
beforeEach(() => {
ChargingModuleViewInvoiceService.go.restore()
Sinon.stub(ChargingModuleViewInvoiceService, 'go').resolves({ succeeded: false })
Sinon.stub(ChargingModuleViewInvoiceService, 'go').resolves({
succeeded: false,
response: {
body: {
error: 'Conflict',
message: 'Invoice 2274cd48-2a61-4b73-a9c0-bc5696c5218d has already been rebilled.',
statusCode: 409
}
}
})
})

it('throws an error', async () => {
Expand All @@ -288,6 +314,14 @@ describe('Reissue invoice service', () => {
// element's id
expect(errorResult.reissueInvoiceExternalId).to.equal(CHARGING_MODULE_REISSUE_INVOICE_RESPONSE.invoices[0].id)
})

it('includes the Charging Module response body', async () => {
const errorResult = await expect(ReissueInvoiceService.go(sourceInvoice, reissueBillingBatch)).to.reject()

expect(errorResult.responseBody.error).to.equal('Conflict')
expect(errorResult.responseBody.message).to.equal('Invoice 2274cd48-2a61-4b73-a9c0-bc5696c5218d has already been rebilled.')
expect(errorResult.responseBody.statusCode).to.equal(409)
})
})
})
})
Expand Down