@hung319/opencode-qwen 1.1.6 → 1.1.7
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/qwen/token.js +14 -23
- package/package.json +1 -1
package/dist/qwen/token.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { QWEN_CONSTANTS } from '../constants';
|
|
2
2
|
export async function validateToken(apiKey) {
|
|
3
|
-
//
|
|
4
|
-
// Use a minimal fetch that only checks if the token is valid
|
|
3
|
+
// Validate using the validation endpoint to check if the token is valid and get user info
|
|
5
4
|
try {
|
|
6
|
-
// Only try the validation endpoint first to get user info, as it's more efficient
|
|
7
5
|
const validateController = new AbortController();
|
|
8
6
|
const validateTimeoutId = setTimeout(() => validateController.abort(), 10000); // 10 second timeout
|
|
9
7
|
const validateResponse = await fetch(QWEN_CONSTANTS.VALIDATE_URL, {
|
|
@@ -27,28 +25,21 @@ export async function validateToken(apiKey) {
|
|
|
27
25
|
};
|
|
28
26
|
}
|
|
29
27
|
else {
|
|
30
|
-
//
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
clearTimeout(modelsTimeoutId);
|
|
41
|
-
if (modelsResponse.ok) {
|
|
42
|
-
return {
|
|
43
|
-
apiKey,
|
|
44
|
-
email: 'qwen-token-user', // Fallback to default email if models endpoint was used
|
|
45
|
-
authMethod: 'token'
|
|
46
|
-
};
|
|
28
|
+
// For validation errors, get the error details
|
|
29
|
+
const errorText = await validateResponse.text().catch(() => '');
|
|
30
|
+
let errorMessage = `Token validation failed: ${validateResponse.status}`;
|
|
31
|
+
// Try to parse the error response to get more details
|
|
32
|
+
try {
|
|
33
|
+
const errorJson = JSON.parse(errorText);
|
|
34
|
+
if (errorJson.error && errorJson.error.message) {
|
|
35
|
+
errorMessage = `${errorMessage} - ${errorJson.error.message}`;
|
|
36
|
+
}
|
|
47
37
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
catch (e) {
|
|
39
|
+
// If parsing fails, use the raw error text
|
|
40
|
+
errorMessage = `${errorMessage} - ${errorText}`;
|
|
51
41
|
}
|
|
42
|
+
throw new Error(errorMessage);
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
45
|
catch (error) {
|
package/package.json
CHANGED