@rmdes/indiekit-endpoint-lastfm 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/lastfm-client.js +16 -2
- package/package.json +1 -1
package/lib/lastfm-client.js
CHANGED
|
@@ -58,11 +58,25 @@ export class LastFmClient {
|
|
|
58
58
|
if (!contentType.includes("application/json")) {
|
|
59
59
|
const text = await response.text();
|
|
60
60
|
console.error("[Last.fm] Non-JSON error response:", text.slice(0, 200));
|
|
61
|
-
throw new IndiekitError(`Last.fm API returned ${response.status}: ${response.statusText}`, {
|
|
61
|
+
throw new IndiekitError(`Last.fm API returned ${response.status}: ${response.statusText || "Unknown Error"}`, {
|
|
62
62
|
status: response.status,
|
|
63
|
+
code: "lastfm_api_error",
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
// Parse error response with defensive handling
|
|
67
|
+
let errorBody;
|
|
68
|
+
try {
|
|
69
|
+
errorBody = await response.json();
|
|
70
|
+
} catch {
|
|
71
|
+
errorBody = {};
|
|
72
|
+
}
|
|
73
|
+
throw new IndiekitError(
|
|
74
|
+
errorBody.error_description || errorBody.message || `Last.fm API error ${response.status}`,
|
|
75
|
+
{
|
|
76
|
+
status: response.status,
|
|
77
|
+
code: String(errorBody.error || "lastfm_api_error"),
|
|
78
|
+
}
|
|
79
|
+
);
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
// Handle non-JSON success responses (shouldn't happen but be safe)
|
package/package.json
CHANGED