|
1 | 1 | import { createHash } from 'node:crypto'; |
2 | 2 | import { parse, stringify } from 'node:querystring'; |
| 3 | +import { IncomingMessage } from 'node:http'; |
3 | 4 | import { request, RequestOptions } from 'node:https'; |
4 | 5 |
|
5 | 6 | import { LastFMParams, LastFMUnknownFunction, OptionalConfig } from './types.js'; |
6 | | -import { IncomingMessage } from 'node:http'; |
7 | 7 |
|
8 | 8 | export class LastFMApiRequest<T> { |
9 | 9 | public config: OptionalConfig; |
@@ -91,16 +91,23 @@ export class LastFMApiRequest<T> { |
91 | 91 |
|
92 | 92 | httpRequest.end(); |
93 | 93 | }).then(([response, content]) => { |
94 | | - if(response.headers['content-type'] !== 'application/json') { |
95 | | - throw new LastFMResponseError(`lastfm-ts-api: Expected JSON response but received '${response.headers['content-type']}'`, { response, content }); |
| 94 | + if (response.headers['content-type'] !== 'application/json') { |
| 95 | + throw new LastFMResponseError( |
| 96 | + `lastfm-ts-api: Expected JSON response but received '${response.headers['content-type']}'`, |
| 97 | + { response, content } |
| 98 | + ); |
96 | 99 | } |
97 | 100 |
|
98 | 101 | let data; |
99 | 102 |
|
100 | 103 | try { |
101 | 104 | data = JSON.parse(content); |
102 | 105 | } catch (err) { |
103 | | - throw new LastFMResponseError(`lastfm-ts-api: Unable to parse LastFM API response to JSON.`, { cause: err, response, content }); |
| 106 | + throw new LastFMResponseError(`lastfm-ts-api: Unable to parse LastFM API response to JSON.`, { |
| 107 | + cause: err, |
| 108 | + response, |
| 109 | + content |
| 110 | + }); |
104 | 111 | } |
105 | 112 |
|
106 | 113 | if (data?.error) { |
@@ -187,7 +194,7 @@ export class LastFMResponseError extends Error { |
187 | 194 | public response?: IncomingMessage; |
188 | 195 | public content?: string; |
189 | 196 |
|
190 | | - public constructor(message: string, options?: ErrorOptions & { response?: IncomingMessage, content?: string }) { |
| 197 | + public constructor(message: string, options?: ErrorOptions & { response?: IncomingMessage; content?: string }) { |
191 | 198 | super(message, options); |
192 | 199 | this.name = 'LastFMResponseError'; |
193 | 200 | const { content, response } = options ?? {}; |
|
0 commit comments