Skip to content

Commit 83367a7

Browse files
feat(cli): Improve error message when authentication is required (#80)
1 parent f80e302 commit 83367a7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

templates/cli/lib/client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
SDK_LANGUAGE,
1818
SDK_VERSION,
1919
SDK_TITLE,
20+
EXECUTABLE_NAME,
2021
} from "./constants.js";
2122

2223
class Client {
@@ -239,6 +240,22 @@ class Client {
239240
globalConfig.setCurrentSession("");
240241
globalConfig.removeSession(current);
241242
}
243+
244+
const isUnauthorized =
245+
json.code === 401 &&
246+
json.type === "general_unauthorized_scope" &&
247+
typeof json.message === "string" &&
248+
/role:\s*guests/i.test(json.message);
249+
250+
if (isUnauthorized) {
251+
throw new AppwriteException(
252+
`You are not authenticated. Run '${EXECUTABLE_NAME} login' to authenticate and try again.`,
253+
json.code,
254+
json.type,
255+
text,
256+
);
257+
}
258+
242259
throw new AppwriteException(
243260
json.message || text,
244261
json.code,

0 commit comments

Comments
 (0)