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.
- package/package.json +1 -1
- package/src/v1.1.js +29 -1
package/package.json
CHANGED
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
|
-
|
|
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
|
}
|