Skip to content

Commit be2210d

Browse files
author
Sagar Miglani
committed
feat: page relationships api in case of MSM and lang copies
1 parent d331c4a commit be2210d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/controllers/page-relationships.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ function PageRelationshipsController(ctx) {
280280
if (e instanceof ErrorWithStatusCode) {
281281
return badRequest(e.message);
282282
}
283-
return badRequest('Missing Authorization header - 2');
283+
const detail = [e.statusCode, e.status, e.message].filter(Boolean).join(' ') || e.message || 'Unknown error';
284+
return badRequest(`Problem getting IMS token: ${detail}`);
284285
}
285286

286287
const { relationships, errors } = await lookupRelationships(site, pages, imsToken, {

test/controllers/page-relationships.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe('Page Relationships Controller', () => {
269269
expect(resolvePageIdsStub).to.not.have.been.called;
270270
});
271271

272-
it('returns 400 with default message when non-ErrorWithStatusCode is thrown', async () => {
272+
it('returns 400 with IMS token problem message when non-ErrorWithStatusCode is thrown', async () => {
273273
isAEMAuthoredSiteStub.returns(true);
274274
getIMSPromiseTokenStub.rejects(new Error('unexpected'));
275275
const controller = PageRelationshipsController(controllerContext);
@@ -278,7 +278,20 @@ describe('Page Relationships Controller', () => {
278278
const body = await response.json();
279279

280280
expect(response.status).to.equal(400);
281-
expect(body.message).to.equal('Missing Authorization header');
281+
expect(body.message).to.equal('Problem getting IMS token: unexpected');
282+
expect(resolvePageIdsStub).to.not.have.been.called;
283+
});
284+
285+
it('returns 400 with Unknown error when thrown error has no message', async () => {
286+
isAEMAuthoredSiteStub.returns(true);
287+
getIMSPromiseTokenStub.rejects(Object.assign(new Error(), { message: '' }));
288+
const controller = PageRelationshipsController(controllerContext);
289+
290+
const response = await controller.getForOpportunity(requestContext);
291+
const body = await response.json();
292+
293+
expect(response.status).to.equal(400);
294+
expect(body.message).to.equal('Problem getting IMS token: Unknown error');
282295
expect(resolvePageIdsStub).to.not.have.been.called;
283296
});
284297

0 commit comments

Comments
 (0)