Projekt

Obecné

Profil

« Předchozí | Další » 

Revize dde3db30

Přidáno uživatelem Jan Pašek před téměř 4 roky(ů)

Re #8587 - Error handling improved in all javascript files

Zobrazit rozdíly:

static/js/certificate.js
89 89
                        this.issuerLoaded = true;
90 90
                    } else {
91 91
                        // certificate does not exists
92
                        console.error("Required certificate does not exists");
93
                        this.showError("Error occurred while loading issuer's details.");
92
                        console.error(response.data["data"]);
93
                        this.errorMessage = "Error occurred while loading issuer's details.";
94 94
                    }
95 95
                } catch (error) {
96 96
                    console.error(error);
97
                    this.showError("Error occurred while loading issuer's details.");
97
                    this.errorMessage = "Error occurred while loading issuer's details.";
98 98
                }
99 99
            }
100 100
            this.displayIssuer = ~this.displayIssuer;
101 101
        },
102 102
        onCertificateDownload: async function () {
103
            await onCertificateDownload(this.id);
103
            try {
104
                await onCertificateDownload(this.id);
105
            }
106
            catch (err) {
107
                this.errorMessage = err.message;
108
            }
104 109
        },
105 110
        onRootDownload: async function () {
106
            await onCertificateRootDownload(this.id);
111
            try {
112
                await onCertificateRootDownload(this.id);
113
            }
114
            catch (err) {
115
                this.errorMessage = err.message;
116
            }
107 117
        },
108 118
        onChainDownload: async function () {
109
            await onCertificateChainDownload(this.id);
119
            try {
120
                await onCertificateChainDownload(this.id);
121
            }
122
            catch (err) {
123
                this.errorMessage = err.message;
124
            }
110 125
        },
111 126
        onPublicKeyDownload: async function () {
112
            await onPublicKeyDownload(this.id);
127
            try {
128
                await onPublicKeyDownload(this.id);
129
            }
130
            catch (err) {
131
                this.errorMessage = err.message;
132
            }
113 133
        },
114 134
        onPrivateKeyDownload: async function () {
115
            await onPrivateKeyDownload(this.id);
135
            try {
136
                await onPrivateKeyDownload(this.id);
137
            }
138
            catch (err) {
139
                this.errorMessage = err.message;
140
            }
116 141
        },
117 142
        onIdentityDownload: async function() {
118
            this.errorMessage = "";
119
            if (this.identityName === "") {
120
                this.errorMessage = "Identity name must not be empty! Please try again.";
121
                document.body.scrollTop = 0;
122
                document.documentElement.scrollTop = 0;
123
                return;
124
            }
125
            await onIdentityDownload(this.id, this.identityName, this.identityPass);
143
            try {
144
                this.errorMessage = "";
145
                if (this.identityName === "") {
146
                    this.errorMessage = "Identity name must not be empty! Please try again.";
147
                    document.body.scrollTop = 0;
148
                    document.documentElement.scrollTop = 0;
149
                    return;
150
                }
151
                await onIdentityDownload(this.id, this.identityName, this.identityPass);
152
            } catch (err) {
153
                this.errorMessage = err.message;
154
            }
126 155
        },
127 156
        onRevoke: async function () {
128 157
            document.body.scrollTop = 0;
......
136 165
                    this.certificate.status="revoked";
137 166
                    certificateDetailsApp.successMessage = "Certificate revocation successful.";
138 167
                } else {
168
                    console.error(response.data["data"]);
139 169
                    certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!";
140 170
                }
141 171
            } catch (error) {
172
                console.error(error);
142 173
                certificateDetailsApp.errorMessage = "An error occurred while revoking certificate";
143 174
            }
144 175
        },
......
150 181
                if (response.data["success"]) {
151 182
                    window.location.href = "/static/index.html?success=Certificate+successfully+deleted";
152 183
                } else {
184
                    console.error(response.data["data"]);
153 185
                    certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!";
154 186
                }
155 187
            } catch (error) {
188
                console.error(error);
156 189
                certificateDetailsApp.errorMessage = "An error occurred while deleting certificate";
157 190
            }
158 191
        }
......
177 210
                    } else {
178 211
                        // certificate does not exists
179 212
                        console.error("Required certificate does not exists");
213
                        console.error(response.data["data"])
180 214
                        certificateDetailsApp.loading = false;
181 215
                        certificateDetailsApp.error = true;
182 216
                    }
......
214 248
                certificateDetailsApp.issuedCertificates = [];
215 249
            }
216 250
        } catch (error) {
217
            console.log(error);
251
            console.error(error);
218 252
        }
219 253
        this.loading = false;
220 254
        this.error = false;
static/js/create_certificate.js
66 66
            if (response.data["success"]) {
67 67
                createCertificateApp.authorities = response.data["data"];
68 68
            } else {
69
                createCertificateApp.authorities = []
69
                this.showError("Error occurred while downloading list of available CAs");
70
                console.error(response.data["data"]);
71
                createCertificateApp.authorities = [];
70 72
            }
71 73
        } catch (error) {
74
            this.showError("Error occurred while downloading list of available CAs");
72 75
            console.log(error);
73 76
        }
74 77
    },
......
93 96
        // handle certificate creation request
94 97
        onCreateCertificate: async function () {
95 98
            // validate input data
99
            // - validate if is self signed or CA is selected
96 100
            // - validate if subject CN is filled in
101
            // - validate if C is either empty or has exactly 2 characters
97 102
            if (!this.isSelfSigned && this.certificateData.CA == null) {
98 103
                this.showError("Issuer must be selected or 'Self-signed' option must be checked!")
99 104
                return;
......
142 147
                }
143 148
                // on error display server response message
144 149
                else {
150
                    console.error(response.data["data"]);
145 151
                    createCertificateApp.showError(response.data["data"]);
146 152
                }
147 153
            } catch (error) {
148
                createCertificateApp.showError(error.response.data["data"]);
154
                createCertificateApp.showError("An error occurred while creating a certificate.");
149 155
                console.error(error);
150 156
            }
151 157
        }
static/js/index.js
43 43
        },
44 44
        loadPage: async function (page, perPage) {
45 45
            // download a list of all available certificates and display them in the table
46
            this.errorMessage = "";
46 47
            try {
47 48
                var params = {
48 49
                    page: page - 1,
......
59 60
                    this.hasPreviousPage = page > 1;
60 61
                    this.hasNextPage = await this.checkIfNextPage(page, this.certificatesPerPage);
61 62
                }
63
                else {
64
                    this.errorMessage = "Error occurred while loading certificate page.";
65
                    console.error(response.data["data"]);
66
                }
62 67
            } catch (error) {
68
                this.errorMessage = "Error occurred while loading certificate page.";
63 69
                console.log(error);
64 70
            }
65 71
        },
......
119 125
                if (response.data["success"]) {
120 126
                    return response.data["data"].length > 0;
121 127
                }
128
                this.errorMessage = "Error occurred while loading certificate page.";
122 129
                return false;
123 130
            } catch (error) {
131
                this.errorMessage = "Error occurred while loading certificate page.";
132
                console.error(error);
124 133
                return false;
125 134
            }
126 135
        }
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