@rmdes/indiekit-endpoint-lastfm 1.0.1 → 1.0.2

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.
@@ -50,10 +50,28 @@ export class LastFmClient {
50
50
  },
51
51
  });
52
52
 
53
+ // Check content type before parsing
54
+ const contentType = response.headers.get("content-type") || "";
55
+
53
56
  if (!response.ok) {
57
+ // Handle non-JSON error responses (e.g., HTML error pages)
58
+ if (!contentType.includes("application/json")) {
59
+ const text = await response.text();
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}`, {
62
+ status: response.status,
63
+ });
64
+ }
54
65
  throw await IndiekitError.fromFetch(response);
55
66
  }
56
67
 
68
+ // Handle non-JSON success responses (shouldn't happen but be safe)
69
+ if (!contentType.includes("application/json")) {
70
+ const text = await response.text();
71
+ console.error("[Last.fm] Unexpected non-JSON response:", text.slice(0, 200));
72
+ throw new Error("Last.fm API returned non-JSON response");
73
+ }
74
+
57
75
  const data = await response.json();
58
76
 
59
77
  // Check for Last.fm API errors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-lastfm",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Last.fm scrobble and listening activity endpoint for Indiekit. Display listening history, loved tracks, and statistics.",
5
5
  "keywords": [
6
6
  "indiekit",