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

Zaptyp / spotify-web-api-node / 16039825477

03 Jul 2025 01:59AM UTC coverage: 95.264%. Remained the same
16039825477

Pull #31

travis-ci

web-flow
Bump jest from 30.0.0 to 30.0.4

Bumps [jest](https://github.com/jestjs/jest/tree/HEAD/packages/jest) from 30.0.0 to 30.0.4.
- [Release notes](https://github.com/jestjs/jest/releases)
- [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jestjs/jest/commits/v30.0.4/packages/jest)

---
updated-dependencies:
- dependency-name: jest
  dependency-version: 30.0.4
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #31: Bump jest from 30.0.0 to 30.0.4

170 of 185 branches covered (91.89%)

Branch coverage included in aggregate %.

353 of 364 relevant lines covered (96.98%)

70.25 hits per line

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

96.12
/src/http-manager.js
1
'use strict';
2

3
var {
4
  TimeoutError,
5
  WebapiError,
6
  WebapiRegularError,
7
  WebapiAuthenticationError,
8
  WebapiPlayerError,
9
  WebapiRatelimitError
10
} = require('./response-error');
4✔
11

12
var HttpManager = {};
4✔
13

14
/* Create superagent options from the base request */
15
var _getParametersFromRequest = function (request) {
4✔
16
  var options = {};
288✔
17

18
  if (request.getQueryParameters()) {
288✔
19
    options.query = new URLSearchParams(
158✔
20
      request.getQueryParameters()
21
    ).toString();
22
  }
23

24
  if (
288✔
25
    request.getHeaders() &&
227✔
26
    request.getHeaders()['Content-Type'] === 'application/json'
27
  ) {
28
    options.data = JSON.stringify(request.getBodyParameters());
54✔
29
  } else if (request.getBodyParameters()) {
234✔
30
    options.data = request.getBodyParameters();
10✔
31
  }
32

33
  if (request.getHeaders()) {
288✔
34
    options.headers = request.getHeaders();
166✔
35
  }
36

37
  if (request.getTimeout()) {
288✔
38
    options.timeout = request.getTimeout();
2✔
39
  }
40

41
  return options;
288✔
42
};
43

44
/**
45
 * @param {Response} response
46
 */
47
var _toError = async function (response) {
4✔
48
  let body
49
  let response2
50
  try {
14✔
51
    response2 = response.clone();
14✔
52
    body = await response.json();
14✔
53
  } catch (e) {
54
    body = await response2.text();
×
55
  }
56

57
  if (
14✔
58
    typeof body === 'object' &&
17✔
59
    typeof body.error === 'object' &&
60
    typeof body.error.reason === 'string'
61
  ) {
62
    return new WebapiPlayerError(body, response.headers, response.status);
2✔
63
  }
64

65
  if (typeof body === 'object' && typeof body.error === 'object') {
12✔
66
    return new WebapiRegularError(body, response.headers, response.status);
6✔
67
  }
68

69
  if (typeof body === 'object' && typeof body.error === 'string') {
6✔
70
    return new WebapiAuthenticationError(
4✔
71
      body,
72
      response.headers,
73
      response.status
74
    );
75
  }
76

77
  if (response.status === 429) {
2!
78
    return new WebapiRatelimitError(body, response.headers, response.status);
×
79
  }
80

81
  /* Other type of error, or unhandled Web API error format */
82
  return new WebapiError(body, response.headers, response.status, body);
2✔
83
};
84

85
/* Make the request to the Web API */
86
HttpManager._makeRequest = function (method, options, uri, callback) {
4✔
87
  if (typeof callback !== 'function') {
288!
88
    throw new TypeError('Expected callback to be a function');
×
89
  }
90

91
  const headers = new Headers(options.headers || {});
288✔
92
  let serializationMethod = JSON.stringify;
288✔
93

94
  if (headers.get('Content-Type') === 'application/x-www-form-urlencoded') {
288✔
95
    serializationMethod = d => new URLSearchParams(d);
8✔
96
  }
97

98
  const controller = new AbortController();
288✔
99
  let timeoutId;
100

101
  if (options.timeout) {
288✔
102
    timeoutId = setTimeout(() => {
2✔
103
      controller.abort();
2✔
104
    }, options.timeout);
105
  }
106

107
  let body = options.data;
288✔
108

109
  if (body && typeof body !== 'string') {
288✔
110
    body = serializationMethod(body);
8✔
111
  }
112

113
  const fullUri = uri + (options.query ? '?' + options.query : '');
288✔
114

115
  fetch(fullUri, {
288✔
116
    method,
117
    headers,
118
    body,
119
    signal: controller.signal
120
  })
121
    .then(async resp => {
122
      clearTimeout(timeoutId);
284✔
123

124
      if (!resp.ok) {
284✔
125
        return callback(await _toError(resp));
14✔
126
      }
127

128
      return callback(null, {
270✔
129
        body: await resp.json().catch(() => null),
78✔
130
        headers: resp.headers,
131
        statusCode: resp.status
132
      });
133
    })
134
    .catch(err => {
135
      clearTimeout(timeoutId);
4✔
136

137
      if (controller.signal.aborted) {
4✔
138
        return callback(
2✔
139
          new TimeoutError(`request took longer than ${options.timeout}ms`)
140
        );
141
      }
142

143
      return callback(err);
2✔
144
    });
145
};
146

147
/**
148
 * Make a HTTP GET request.
149
 * @param {BaseRequest} The request.
150
 * @param {Function} The callback function.
151
 */
152
HttpManager.get = function (request, callback) {
4✔
153
  var options = _getParametersFromRequest(request);
180✔
154
  var method = 'GET';
180✔
155

156
  HttpManager._makeRequest(method, options, request.getURI(), callback);
180✔
157
};
158

159
/**
160
 * Make a HTTP POST request.
161
 * @param {BaseRequest} The request.
162
 * @param {Function} The callback function.
163
 */
164
HttpManager.post = function (request, callback) {
4✔
165
  var options = _getParametersFromRequest(request);
30✔
166
  var method = 'POST';
30✔
167

168
  HttpManager._makeRequest(method, options, request.getURI(), callback);
30✔
169
};
170

171
/**
172
 * Make a HTTP DELETE request.
173
 * @param {BaseRequest} The request.
174
 * @param {Function} The callback function.
175
 */
176
HttpManager.del = function (request, callback) {
4✔
177
  var options = _getParametersFromRequest(request);
22✔
178
  var method = 'DELETE';
22✔
179

180
  HttpManager._makeRequest(method, options, request.getURI(), callback);
22✔
181
};
182

183
/**
184
 * Make a HTTP PUT request.
185
 * @param {BaseRequest} The request.
186
 * @param {Function} The callback function.
187
 */
188
HttpManager.put = function (request, callback) {
4✔
189
  var options = _getParametersFromRequest(request);
56✔
190
  var method = 'PUT';
56✔
191

192
  HttpManager._makeRequest(method, options, request.getURI(), callback);
56✔
193
};
194

195
module.exports = HttpManager;
4✔
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