Skip to content

Commit f5e9ae6

Browse files
committed
New API Key tester
1 parent 1ae352e commit f5e9ae6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/APIManager.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ export class SquareCloudAPIError extends Error {
1717
}
1818

1919
export class APIManager {
20-
constructor(private apiKey: string) {}
20+
constructor(private apiKey: string) {
21+
this.testApiKey();
22+
}
23+
24+
private async testApiKey() {
25+
try {
26+
await this.fetch('user');
27+
} catch {
28+
throw new SquareCloudAPIError('INVALID_API_KEY')
29+
}
30+
}
2131

2232
private async fetch(path: string, options: AxiosRequestConfig = {}) {
2333
options.headers = {

0 commit comments

Comments
 (0)