mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
refactor: refine the error message
This commit is contained in:
parent
e5fd2ba280
commit
e8db014336
@ -45,7 +45,7 @@ class GatewayService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Login failed");
|
throw new Error(`Gateway login failed: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.parseLoginResponse(response.data);
|
return this.parseLoginResponse(response.data);
|
||||||
|
@ -36,8 +36,9 @@ export type PortalCredential = {
|
|||||||
class PortalService {
|
class PortalService {
|
||||||
async prelogin(portal: string): Promise<Prelogin> {
|
async prelogin(portal: string): Promise<Prelogin> {
|
||||||
const preloginUrl = `https://${portal}/global-protect/prelogin.esp`;
|
const preloginUrl = `https://${portal}/global-protect/prelogin.esp`;
|
||||||
|
let response;
|
||||||
try {
|
try {
|
||||||
const response = await fetch<string>(preloginUrl, {
|
response = await fetch<string>(preloginUrl, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "PAN GlobalProtect",
|
"User-Agent": "PAN GlobalProtect",
|
||||||
@ -57,14 +58,15 @@ class PortalService {
|
|||||||
// "host-id": "TODO, mac address?",
|
// "host-id": "TODO, mac address?",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to prelogin: Network error", err);
|
||||||
|
throw new Error("Failed to prelogin: Network error");
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to prelogin: ${response.status}`);
|
throw new Error(`Failed to prelogin: ${response.status}`);
|
||||||
}
|
}
|
||||||
return this.parsePrelogin(response.data);
|
return this.parsePrelogin(response.data);
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Failed to prelogin: Network error`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private parsePrelogin(response: string): Prelogin {
|
private parsePrelogin(response: string): Prelogin {
|
||||||
|
Loading…
Reference in New Issue
Block a user