Skip to content

Commit 9ecb072

Browse files
committed
better error messages
1 parent 14a638b commit 9ecb072

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

auth.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export async function getAuth(
162162
return storedAuth;
163163
}
164164

165-
const { code, exchangeToken, verifier } = await interactive(deployUrl);
165+
const { code, exchangeToken, verifier } = await interactive(debug, deployUrl);
166166

167167
const authUrl = `${deployUrl}/auth?code=${code}`;
168168

@@ -181,7 +181,7 @@ export async function getAuth(
181181
);
182182
}
183183

184-
export async function interactive(deployUrl: string): Promise<
184+
export async function interactive(debug: boolean, deployUrl: string): Promise<
185185
{ code: string; exchangeToken: string; verifier: string }
186186
> {
187187
const verifier = crypto.randomUUID();
@@ -195,7 +195,11 @@ export async function interactive(deployUrl: string): Promise<
195195
});
196196

197197
if (!res.ok) {
198-
console.error("An error occured, exiting...");
198+
console.error("An error occurred during authentication, exiting...");
199+
if (debug) {
200+
console.log(res);
201+
console.log(await res.json());
202+
}
199203
Deno.exit(1);
200204
}
201205

create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function create(
4141
const storedAuth = token_storage.get();
4242

4343
if (!storedAuth) {
44-
const res = await interactive(deployUrl);
44+
const res = await interactive(debug, deployUrl);
4545
url.searchParams.set("code", res.code);
4646
verifier = res.verifier;
4747
exchangeToken = res.exchangeToken;

token_storage.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ let cachedToken: string | null = null;
22
let tokenIsTemp = false;
33
let cannotInteractWithKeychain = false;
44

5+
const KEYCHAIN_WARNING =
6+
"Unable to interact with keychain.\nThe authentication will not be stored and will only work on this execution.";
7+
58
export default {
69
get(): string | null {
710
if (cachedToken) {
@@ -13,7 +16,7 @@ export default {
1316
} catch {
1417
if (!cannotInteractWithKeychain) {
1518
cannotInteractWithKeychain = true;
16-
console.log("Unable to interact with keychain.");
19+
console.log(KEYCHAIN_WARNING);
1720
}
1821
return null;
1922
}
@@ -28,7 +31,7 @@ export default {
2831
} catch {
2932
if (!cannotInteractWithKeychain) {
3033
cannotInteractWithKeychain = true;
31-
console.log("Unable to interact with keychain.");
34+
console.log(KEYCHAIN_WARNING);
3235
}
3336
}
3437
} else {
@@ -46,7 +49,7 @@ export default {
4649
} catch {
4750
if (!cannotInteractWithKeychain) {
4851
cannotInteractWithKeychain = true;
49-
console.log("Unable to interact with keychain.");
52+
console.log(KEYCHAIN_WARNING);
5053
}
5154
}
5255
},

0 commit comments

Comments
 (0)