@authn8/mcp-server 1.1.2 → 1.1.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/dist/index.js +29 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,6 +21,28 @@ var Authn8Error = class extends Error {
|
|
|
21
21
|
};
|
|
22
22
|
var accountsCache = null;
|
|
23
23
|
var CACHE_TTL_MS = 60 * 1e3;
|
|
24
|
+
async function readApiError(response) {
|
|
25
|
+
try {
|
|
26
|
+
const body = await response.json();
|
|
27
|
+
if (Array.isArray(body.errors)) {
|
|
28
|
+
const messages = body.errors.filter(
|
|
29
|
+
(error) => typeof error === "string" && error.length > 0
|
|
30
|
+
);
|
|
31
|
+
if (messages.length > 0) {
|
|
32
|
+
return messages.join(" ");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof body.detail === "string" && body.detail.length > 0) {
|
|
36
|
+
return body.detail;
|
|
37
|
+
}
|
|
38
|
+
if (typeof body.title === "string" && body.title.length > 0) {
|
|
39
|
+
return body.title;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
24
46
|
async function apiRequest(endpoint, method = "GET") {
|
|
25
47
|
if (!API_KEY) {
|
|
26
48
|
throw new Authn8Error(
|
|
@@ -39,10 +61,16 @@ async function apiRequest(endpoint, method = "GET") {
|
|
|
39
61
|
if (!response.ok) {
|
|
40
62
|
if (response.status === 401) {
|
|
41
63
|
throw new Authn8Error(
|
|
42
|
-
"Token is invalid or
|
|
64
|
+
"Token is invalid, expired or revoked. Check it under Settings > MCP Tokens in Authn8.",
|
|
43
65
|
401
|
|
44
66
|
);
|
|
45
67
|
}
|
|
68
|
+
if (response.status !== 429) {
|
|
69
|
+
const apiMessage = await readApiError(response);
|
|
70
|
+
if (apiMessage) {
|
|
71
|
+
throw new Authn8Error(apiMessage, response.status);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
46
74
|
if (response.status === 403) {
|
|
47
75
|
throw new Authn8Error(
|
|
48
76
|
"Token does not have permission to access this resource.",
|