emusks 2.0.16 → 2.0.17

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/v1.1.js +29 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emusks",
3
- "version": "2.0.16",
3
+ "version": "2.0.17",
4
4
  "description": "Reverse-engineered Twitter API client. Log in and interact with the unofficial X API using any client identity — web, Android, iOS, or TweetDeck",
5
5
  "keywords": [
6
6
  "client",
package/src/v1.1.js CHANGED
@@ -48,7 +48,7 @@ export default async function v1_1(queryName, { params, body, headers } = {}) {
48
48
 
49
49
  const cycleTLS = await getCycleTLS();
50
50
 
51
- return await cycleTLS(
51
+ const res = await cycleTLS(
52
52
  finalUrl,
53
53
  {
54
54
  headers: requestHeaders,
@@ -61,4 +61,32 @@ export default async function v1_1(queryName, { params, body, headers } = {}) {
61
61
  },
62
62
  method,
63
63
  );
64
+
65
+ // surface twitter errors instead of returning silently. matches the pattern
66
+ // in graphql.js (it checks res.errors after .json()). without this, callers
67
+ // that just `await res.json()` swallow 4xx error bodies — e.g. profile
68
+ // updates over 160 chars used to no-op silently.
69
+ let bodyText;
70
+ try {
71
+ bodyText = await res.text();
72
+ } catch {
73
+ return res;
74
+ }
75
+ let bodyJson;
76
+ if (bodyText) {
77
+ try { bodyJson = JSON.parse(bodyText); } catch {}
78
+ }
79
+ if (bodyJson?.errors?.length) {
80
+ const messages = bodyJson.errors
81
+ .map((e) => e.message || (e.code != null ? `code ${e.code}` : "unknown"))
82
+ .join("; ");
83
+ throw new Error(`twitter v1.1 ${queryName} ${res.status}: ${messages}`);
84
+ }
85
+ // re-expose the response so existing helpers keep working
86
+ return {
87
+ status: res.status,
88
+ headers: res.headers,
89
+ json: async () => bodyJson,
90
+ text: async () => bodyText,
91
+ };
64
92
  }