• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cofacts / rumors-line-bot / 13617472365

02 Mar 2025 09:20AM UTC coverage: 90.761% (-0.2%) from 90.989%
13617472365

push

github

web-flow
Merge pull request #403 from cofacts/network0error-handling

Handle network errors

541 of 641 branches covered (84.4%)

Branch coverage included in aggregate %.

12 of 18 new or added lines in 6 files covered. (66.67%)

1 existing line in 1 file now uncovered.

1129 of 1199 relevant lines covered (94.16%)

12.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.27
/src/webhook/lineClient.js
1
import fetch from 'node-fetch';
2
import rollbar from 'src/lib/rollbar';
3

4
export default { post, get, getContent };
5

6
async function post(endpoint = '', body = {}, options = {}) {
10!
7
  const URL = `https://api.line.me/v2/bot${endpoint}`;
10✔
8
  const resp = await fetch(URL, {
10✔
9
    method: 'POST',
10
    headers: {
11
      'Content-Type': 'application/json',
12
      Authorization: `Bearer ${process.env.LINE_CHANNEL_TOKEN}`,
13
      ...options.headers,
14
    },
15
    ...options,
16
    body: JSON.stringify(body),
17
  });
18

19
  const result = await resp.json();
10✔
20

21
  if (resp.status !== 200) {
9!
22
    console.error(JSON.stringify(result, null, '  '));
9✔
23

24
    rollbar.error(
9✔
25
      `[LINE Client] ${resp.status}: ${result.message}.`,
26
      {
27
        // Request object for rollbar server SDK
28
        headers: options.headers,
29
        body: JSON.stringify(body),
30
        url: URL,
31
        method: 'POST',
32
      },
33
      { result }
34
    );
35
  }
36

37
  return result;
9✔
38
}
39

40
async function get(endpoint = '', options = {}) {
×
41
  const URL = `https://api.line.me/v2/bot${endpoint}`;
×
42
  const resp = await fetch(URL, {
×
43
    method: 'GET',
44
    headers: {
45
      'Content-Type': 'application/json',
46
      Authorization: `Bearer ${process.env.LINE_CHANNEL_TOKEN}`,
47
      ...options.headers,
48
    },
49
    ...options,
50
  });
51

52
  const result = await resp.json();
×
53

54
  if (resp.status !== 200) {
×
55
    console.error(JSON.stringify(result, null, '  '));
×
56

57
    rollbar.error(
×
58
      `[LINE Client] ${resp.status}: ${result.message}.`,
59
      {
60
        // Request object for rollbar server SDK
61
        headers: options.headers,
62
        url: URL,
63
        method: 'GET',
64
      },
65
      { result }
66
    );
67
  }
68

69
  return result;
×
70
}
71

72
async function getContent(messageId, options = {}) {
×
73
  // this endpoint is for sending and receiving large amounts of data in the LINE platform for Messaging API.
74
  // https://developers.line.biz/en/reference/messaging-api/#get-content
75
  const URL = `https://api-data.line.me/v2/bot/message/${messageId}/content`;
×
76
  const resp = await fetch(URL, {
×
77
    method: 'GET',
78
    headers: {
79
      Authorization: `Bearer ${process.env.LINE_CHANNEL_TOKEN}`,
80
      ...options.headers,
81
    },
82
    ...options,
83
  });
84

85
  if (resp.status !== 200) {
×
86
    const err = await resp.json();
×
NEW
87
    console.error('[LINE Client]', JSON.stringify(err, null, '  '));
×
88

89
    rollbar.error(
×
90
      `[LINE Client] ${resp.status}: ${err.message}.`,
91
      {
92
        // Request object for rollbar server SDK
93
        headers: options.headers,
94
        url: URL,
95
        method: 'GET',
96
      },
97
      { result: err }
98
    );
99
  }
100

101
  return resp;
×
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc