Revize dde3db30
Přidáno uživatelem Jan Pašek před téměř 4 roky(ů)
static/js/utilities.js | ||
---|---|---|
42 | 42 |
* @param id identifier of certificate to be downloaded |
43 | 43 |
*/ |
44 | 44 |
async function onCertificateDownload(id) { |
45 |
var success = false; |
|
45 | 46 |
try { |
46 | 47 |
const response = await axios.get(API_URL + "certificates/" + id); |
47 | 48 |
if (response.data["success"]) { |
49 |
success = true; |
|
48 | 50 |
download(id + ".pem", response.data["data"]) |
49 |
} else |
|
50 |
console.log("Error occurred while downloading the certificate") // TODO more action may be required |
|
51 |
} else { |
|
52 |
console.error("Error occurred while downloading the certificate"); |
|
53 |
console.error(response.data["data"]); |
|
54 |
} |
|
51 | 55 |
} catch (error) { |
52 | 56 |
console.log(error); |
53 | 57 |
} |
58 |
if (!success) throw new Error("Error occurred while obtaining the requested data!"); |
|
54 | 59 |
} |
55 | 60 |
|
56 | 61 |
/** |
... | ... | |
58 | 63 |
* @param id identifier of certificate whose chain shall be downloaded |
59 | 64 |
*/ |
60 | 65 |
async function onCertificateChainDownload(id) { |
66 |
var success = false; |
|
61 | 67 |
try { |
62 | 68 |
const response = await axios.get(API_URL + "certificates/" + id + "/chain"); |
63 | 69 |
if (response.data["success"]) { |
70 |
success = true; |
|
64 | 71 |
download(id + "_chain.pem", response.data["data"]) |
65 |
} else |
|
66 |
console.log("Error occurred while downloading the certificate's chain of trust") // TODO more action may be required |
|
72 |
} else { |
|
73 |
console.error("Error occurred while downloading the certificate's chain of trust"); |
|
74 |
console.error(response.data["data"]); |
|
75 |
} |
|
67 | 76 |
} catch (error) { |
68 | 77 |
console.log(error); |
69 | 78 |
} |
79 |
if (!success) throw new Error("Error occurred while obtaining the requested data!"); |
|
70 | 80 |
} |
71 | 81 |
|
72 | 82 |
/** |
... | ... | |
74 | 84 |
* @param id identifier of certificate whose root shall be downloaded |
75 | 85 |
*/ |
76 | 86 |
async function onCertificateRootDownload(id) { |
87 |
var success = false; |
|
77 | 88 |
try { |
78 | 89 |
const response = await axios.get(API_URL + "certificates/" + id + "/root"); |
79 | 90 |
if (response.data["success"]) { |
91 |
success = true; |
|
80 | 92 |
download(id + "_root.pem", response.data["data"]) |
81 |
} else |
|
82 |
console.log("Error occurred while downloading the certificate's root CA") // TODO more action may be required |
|
93 |
} else { |
|
94 |
console.error("Error occurred while downloading the certificate's root CA"); |
|
95 |
console.error(response.data["data"]); |
|
96 |
} |
|
83 | 97 |
} catch (error) { |
84 | 98 |
console.log(error); |
85 | 99 |
} |
100 |
if (!success) throw new Error("Error occurred while obtaining the requested data!"); |
|
86 | 101 |
} |
87 | 102 |
|
88 | 103 |
/** |
... | ... | |
90 | 105 |
* @param id identifier of certificate whose pub. key shall be downloaded |
91 | 106 |
*/ |
92 | 107 |
async function onPublicKeyDownload(id) { |
108 |
var success = false; |
|
93 | 109 |
try { |
94 | 110 |
const response = await axios.get(API_URL + "certificates/" + id + "/publickey"); |
95 | 111 |
if (response.data["success"]) { |
112 |
success = true; |
|
96 | 113 |
download(id + "_public_key.pem", response.data["data"]) |
97 |
} else |
|
98 |
console.log("Error occurred while downloading the certificate's public key") // TODO more action may be required |
|
114 |
} else { |
|
115 |
console.error("Error occurred while downloading the certificate's public key") |
|
116 |
console.error(response.data["data"]); |
|
117 |
} |
|
99 | 118 |
} catch (error) { |
100 | 119 |
console.log(error); |
101 | 120 |
} |
121 |
if (!success) throw new Error("Error occurred while obtaining the requested data!"); |
|
102 | 122 |
} |
103 | 123 |
|
104 | 124 |
/** |
... | ... | |
106 | 126 |
* @param id identifier of certificate whose pub. key shall be downloaded |
107 | 127 |
*/ |
108 | 128 |
async function onPrivateKeyDownload(id) { |
129 |
var success = false; |
|
109 | 130 |
try { |
110 | 131 |
const response = await axios.get(API_URL + "certificates/" + id + "/privatekey"); |
111 | 132 |
if (response.data["success"]) { |
133 |
success = true; |
|
112 | 134 |
download(id + "_private_key.pem", response.data["data"]) |
113 |
} else |
|
114 |
console.log("Error occurred while downloading the certificate's private key") // TODO more action may be required |
|
135 |
} else { |
|
136 |
console.error("Error occurred while downloading the certificate's private key"); |
|
137 |
console.error(response.data["data"]); |
|
138 |
} |
|
115 | 139 |
} catch (error) { |
116 | 140 |
console.log(error); |
117 | 141 |
} |
142 |
if (!success) throw new Error("Error occurred while obtaining the requested data!"); |
|
118 | 143 |
} |
119 | 144 |
|
120 | 145 |
/** |
... | ... | |
124 | 149 |
* @param passphrase password protecting the identity |
125 | 150 |
*/ |
126 | 151 |
async function onIdentityDownload(id, name, passphrase) { |
152 |
var success = false; |
|
127 | 153 |
try { |
128 | 154 |
var identityData = { |
129 | 155 |
name: name, |
... | ... | |
136 | 162 |
'Accept': 'application/x-pkcs12 ' |
137 | 163 |
} |
138 | 164 |
}); |
165 |
success = true; |
|
139 | 166 |
downloadBinary(name + ".p12", response.data) |
140 | 167 |
} catch (error) { |
141 | 168 |
console.log(error); |
142 | 169 |
} |
170 |
if (!success) throw new Error("Error occurred while obtaining the requested data!"); |
|
143 | 171 |
} |
Také k dispozici: Unified diff
Re #8587 - Error handling improved in all javascript files