From 286cd69ce8ca21fddb07147c4c375a5a76be55c1 Mon Sep 17 00:00:00 2001 From: link515 Date: Fri, 5 Jul 2019 17:27:30 +0800 Subject: [PATCH] feat(line): return null when no user found --- packages/messaging-api-line/src/LineClient.js | 8 +++++++- .../src/__tests__/LineClient.spec.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/messaging-api-line/src/LineClient.js b/packages/messaging-api-line/src/LineClient.js index 6d065954..7b486292 100644 --- a/packages/messaging-api-line/src/LineClient.js +++ b/packages/messaging-api-line/src/LineClient.js @@ -589,7 +589,13 @@ export default class LineClient { headers: { Authorization: `Bearer ${customAccessToken}` }, } ) - .then(res => res.data, handleError); + .then(res => res.data, handleError) + .catch(err => { + if (err.response && err.response.status === 404) { + return null; + } + handleError(err); + }); } /** diff --git a/packages/messaging-api-line/src/__tests__/LineClient.spec.js b/packages/messaging-api-line/src/__tests__/LineClient.spec.js index 21f59e8b..74fcbf3c 100644 --- a/packages/messaging-api-line/src/__tests__/LineClient.spec.js +++ b/packages/messaging-api-line/src/__tests__/LineClient.spec.js @@ -92,6 +92,18 @@ describe('Profile', () => { expect(res).toEqual(reply); }); + + it('should return null when no user found', async () => { + const { client, mock } = createMock(); + + mock.onGet().reply(404, { + message: 'Not found', + }); + + const res = await client.getUserProfile(RECIPIENT_ID); + + expect(res).toEqual(null); + }); }); });