@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.
@@ -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
- throw await IndiekitError.fromFetch(response);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-lastfm",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",