From 7e2170851bc4c171fff99443ee7d7b5eabb08403 Mon Sep 17 00:00:00 2001 From: Qin Zhao Date: Fri, 27 Sep 2019 18:10:54 +0800 Subject: [PATCH] Catch ASG error --- .../src/controllers/wafpolicy.controller.ts | 4 +-- .../wafpolicy.controller.acceptance.ts | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/waf/src/controllers/wafpolicy.controller.ts b/app/waf/src/controllers/wafpolicy.controller.ts index fd1533d48..928f4c358 100644 --- a/app/waf/src/controllers/wafpolicy.controller.ts +++ b/app/waf/src/controllers/wafpolicy.controller.ts @@ -227,9 +227,7 @@ export class WafpolicyController extends BaseController { wafpolicy.id, ); } catch (error) { - throw new HttpErrors.unprocessableEntity( - 'check wafpolicy from asg service failed', - ); + throw new HttpErrors.UnprocessableEntity(`ASG error: ${error.message}`); } if (!resp || !resp[0]) { diff --git a/app/waf/test/acceptance/wafpolicy.controller.acceptance.ts b/app/waf/test/acceptance/wafpolicy.controller.acceptance.ts index 909e96167..90462fc7e 100644 --- a/app/waf/test/acceptance/wafpolicy.controller.acceptance.ts +++ b/app/waf/test/acceptance/wafpolicy.controller.acceptance.ts @@ -236,6 +236,33 @@ describe('WafpolicyController', () => { }, ); + it( + 'get ' + + prefix + + '/wafpolicies/${id}/adcs/${adcId}: ASG fails when check wafpolicy', + async () => { + const wafpolicy = await givenWafpolicyData(wafapp, { + tenantId: 'a random id', + public: true, + }); + + const adc = await givenAdcData(wafapp, { + management: { + trustedDeviceId: uuid(), + }, + }); + + checkWafpolicyStub.throws(new Error('OMG')); + + const resp = await client + .get(prefix + `/wafpolicies/${wafpolicy.id}/adcs/${adc.id}`) + .set('X-Auth-Token', ExpectedData.userToken) + .set('tenant-id', ExpectedData.tenantId) + .expect(422); + + expect(resp.body.error.message).equal('ASG error: OMG'); + }, + ); it('get ' + prefix + '/wafpolicies: of all', async () => { const wafpolicy = await givenWafpolicyData(wafapp);