Skip to content

Commit

Permalink
Merge pull request #778 from adobecom/dc-hosted-error-detail
Browse files Browse the repository at this point in the history
pass wrappedException object  and log individual fields: type, name and message
  • Loading branch information
TsayAdobe authored Aug 28, 2024
2 parents 027451d + 9a26748 commit 3579270
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
7 changes: 4 additions & 3 deletions acrobat/blocks/dc-converter-widget/dc-converter-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ export default async function init(element) {

window.dispatchEvent(personalizationIsReady);
}).catch((err) => {
const detail = JSON.stringify(err, Object.getOwnPropertyNames(err));
window.dispatchEvent(new CustomEvent('DC_Hosted:Error', { detail }));
window.dispatchEvent(new CustomEvent('DC_Hosted:Error', { detail: { wrappedException: err } }));
});
});

Expand All @@ -348,6 +347,8 @@ export default async function init(element) {
dropZone.innerHTML = '<img src="/acrobat/img/icons/error.svg"><p>We apologize for the inconvenience. We are working hard to make the service available. Please check back shortly.</p>';
document.querySelector('div[class*="DropZoneFooter__dropzoneFooter"]').innerHTML = '';
}
window.lana?.log(`DC Widget failed. message=${JSON.stringify(err.detail?.message)}`, lanaOptions);
const { message, name, type } = err.detail?.wrappedException || {};
const info = `DC Widget failed. type=${type} name=${name} message=${message}`;
window.lana?.log(info, lanaOptions);
});
}
3 changes: 1 addition & 2 deletions acrobat/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ const { ietf } = getLocale(locales);
const imsIsReady = new CustomEvent('IMS:Ready');
window.dispatchEvent(imsIsReady);
}).catch((err) => {
const detail = JSON.stringify(err, Object.getOwnPropertyNames(err));
window.dispatchEvent(new CustomEvent('DC_Hosted:Error', { detail }));
window.dispatchEvent(new CustomEvent('DC_Hosted:Error', { detail: { wrappedException: err } }));
});

loadLana({ clientId: 'dxdc', tags: 'DC_Milo' });
Expand Down
34 changes: 34 additions & 0 deletions test/blocks/dc-converter-widget/dc-converter-widget-error.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable compat/compat */
/* eslint-disable no-underscore-dangle */
/* eslint-disable object-curly-newline */
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';
import { delay } from '../../helpers/waitfor.js';

const { default: init } = await import(
'../../../acrobat/blocks/dc-converter-widget/dc-converter-widget.js'
);

describe('dc-converter-widget block', () => {
before(async () => {
document.head.innerHTML = await readFile({ path: './mocks/head.html' });
document.body.innerHTML = await readFile({ path: './mocks/body_cache.html' });
const block = document.body.querySelector('.dc-converter-widget');
await init(block);
});

afterEach(() => {
sinon.restore();
});

it('handles an error in DC_Hosted:Ready', async () => {
window.lana = { log: sinon.stub() };
window.dc_hosted = {
getUserLimits: async () => null,
};
window.dispatchEvent(new CustomEvent('DC_Hosted:Ready'));
await delay(100);
expect(window.lana.log.getCall(0).args[0]).to.eq('DC Widget failed. type=undefined name=TypeError message=Cannot read properties of null (reading \'upload\')');
});
});
6 changes: 3 additions & 3 deletions test/blocks/dc-converter-widget/dc-converter-widget.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('dc-converter-widget block', () => {
await delay(500);
const errorImg = document.querySelector('div[class*="DCHosted__container"] img');
expect(errorImg.src).to.contain('error.svg');
expect(window.lana.log.getCall(0).args[0]).to.eq('DC Widget failed. message=undefined');
expect(window.lana.log.getCall(0).args[0]).to.eq('DC Widget failed. type=undefined name=undefined message=undefined');
});

it('handle multiple DC_Hosted:Errors', async () => {
Expand All @@ -84,7 +84,7 @@ describe('dc-converter-widget block', () => {
await delay(500);
const errorImg = document.querySelector('div[class*="DCHosted__container"] img');
expect(errorImg.src).to.contain('error.svg');
expect(window.lana.log.getCall(0).args[0]).to.eq('DC Widget failed. message=undefined');
expect(window.lana.log.getCall(1).args[0]).to.eq('DC Widget failed. message=undefined');
expect(window.lana.log.getCall(0).args[0]).to.eq('DC Widget failed. type=undefined name=undefined message=undefined');
expect(window.lana.log.getCall(1).args[0]).to.eq('DC Widget failed. type=undefined name=undefined message=undefined');
});
});

0 comments on commit 3579270

Please sign in to comment.