Skip to content

Commit 3bb8bfd

Browse files
committed
detailed error messages api+front
1 parent 44b860d commit 3bb8bfd

File tree

5 files changed

+42
-28
lines changed

5 files changed

+42
-28
lines changed

frontend/src/components/system/FileUploader.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,34 @@
1515

1616
<script setup lang="ts">
1717
import { Notify, QUploaderFactoryFn } from "quasar";
18-
import { ApiPaths } from "../../types/Api";
18+
import { ApiPaths, ApiResponse, GetApiResponseFromJson } from "../../types/Api";
19+
20+
function onUploaded(info: {files: readonly any[], xhr: XMLHttpRequest}) {
21+
const response: ApiResponse = GetApiResponseFromJson(info.xhr.response);
1922
20-
function onUploaded() {
2123
Notify.create({
2224
type: "positive",
23-
message: `Upload complete.`
25+
message: response.data.response
2426
});
2527
}
2628
2729
function onRejected(rejectedEntries: any) {
2830
console.log(rejectedEntries);
2931
Notify.create({
3032
type: "negative",
31-
message: `${rejectedEntries.length} file(s) did not pass validation constraints`
33+
message: `${rejectedEntries.length} file(s) did not pass validation constraints. File too big?`
3234
});
3335
}
3436
35-
function onFailed(info: {files: readonly any[], xhr: any}) {
37+
function onFailed(info: {files: readonly any[], xhr: XMLHttpRequest}) {
3638
console.log(info.files);
3739
console.log(info.xhr);
40+
41+
const response: ApiResponse = GetApiResponseFromJson(info.xhr.response);
42+
3843
Notify.create({
3944
type: "negative",
40-
message: `Upload failed`
45+
message: "Error! " + response.data.response
4146
});
4247
}
4348

frontend/src/types/Api.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ export enum ApiPaths {
55
Reboot = "/api/system/reboot",
66
DeepSleep = "/api/system/deep_sleep",
77
FactoryReset = "/api/system/factory_reset",
8-
FileUpload ="/upload"
8+
FileUpload = "/upload"
99
}
1010

1111
export interface ApiResponse {
1212
data: {
1313
response: string;
1414
};
1515
}
16+
17+
// Convert JSON API response into ApiResponse
18+
export function GetApiResponseFromJson(jsonText: string): ApiResponse {
19+
if (jsonText === "") {
20+
return { data: { response: "" } };
21+
} else {
22+
return { data: { response: JSON.parse(jsonText).response } };
23+
}
24+
}

main/storage/assets/index-KaZkwgZ2.js renamed to main/storage/assets/index-KTzspj6P.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main/storage/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>ESPRI - ESP Radio Interface</title>
8-
<script type="module" crossorigin src="/assets/index-KaZkwgZ2.js"></script>
8+
<script type="module" crossorigin src="/assets/index-KTzspj6P.js"></script>
99
<link rel="stylesheet" crossorigin href="/index-Iw26f.css">
1010
</head>
1111
<body>

main/web/handlers/static_files.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ esp_err_t STATIC_FILES_Upload(httpd_req_t *req)
180180
{
181181
/* Respond with 500 Internal Server Error */
182182
httpd_json_resp_send(req, HTTPD_500, "Filename too long");
183-
return ESP_FAIL;
183+
return ESP_OK;
184184
}
185185

186186
/* Filename cannot have a trailing '/' */
187187
if (filename[strlen(filename) - 1] == '/')
188188
{
189189
ESP_LOGE(TAG, "Invalid filename : %s", filename);
190190
httpd_json_resp_send(req, HTTPD_500, "Invalid filename");
191-
return ESP_FAIL;
191+
return ESP_OK;
192192
}
193193

194194
#ifdef UPLOAD_PREVENT_FILE_OVERWRITE
@@ -197,7 +197,7 @@ esp_err_t STATIC_FILES_Upload(httpd_req_t *req)
197197
ESP_LOGE(TAG, "File already exists : %s", filepath);
198198
/* Respond with 400 Bad Request */
199199
httpd_json_resp_send(req, HTTPD_400, "File already exists");
200-
return ESP_FAIL;
200+
return ESP_OK;
201201
}
202202
#endif
203203

@@ -206,10 +206,10 @@ esp_err_t STATIC_FILES_Upload(httpd_req_t *req)
206206
{
207207
ESP_LOGE(TAG, "File too large : %d bytes", req->content_len);
208208
/* Respond with 400 Bad Request */
209-
httpd_json_resp_send(req, HTTPD_400, "File size must be less than");
209+
httpd_json_resp_send(req, HTTPD_400, "File size must be less than " MAX_FILE_SIZE_STR);
210210
/* Return failure to close underlying connection else the
211211
* incoming file content will keep the socket busy */
212-
return ESP_FAIL;
212+
return ESP_OK;
213213
}
214214

215215
#ifdef UPLOAD_PREVENT_FILE_OVERWRITE
@@ -222,7 +222,7 @@ esp_err_t STATIC_FILES_Upload(httpd_req_t *req)
222222
{
223223
ESP_LOGE(TAG, "Failed to get enough free space for the file");
224224
httpd_json_resp_send(req, HTTPD_500, "Failed to get enough free space for the file");
225-
return ESP_FAIL;
225+
return ESP_OK;
226226
}
227227
#endif
228228

@@ -232,7 +232,7 @@ esp_err_t STATIC_FILES_Upload(httpd_req_t *req)
232232
ESP_LOGE(TAG, "Failed to create file : %s", filepath);
233233
/* Respond with 500 Internal Server Error */
234234
httpd_json_resp_send(req, HTTPD_500, "Failed to create file");
235-
return ESP_FAIL;
235+
return ESP_OK;
236236
}
237237

238238
ESP_LOGI(TAG, "Receiving file : %s...", filename);
@@ -266,7 +266,7 @@ esp_err_t STATIC_FILES_Upload(httpd_req_t *req)
266266
ESP_LOGE(TAG, "File reception failed!");
267267
/* Respond with 500 Internal Server Error */
268268
httpd_json_resp_send(req, HTTPD_500, "Failed to receive file");
269-
return ESP_FAIL;
269+
return ESP_OK;
270270
}
271271

272272
/* Write buffer content to file on storage */
@@ -280,7 +280,7 @@ esp_err_t STATIC_FILES_Upload(httpd_req_t *req)
280280
ESP_LOGE(TAG, "File write failed!");
281281
/* Respond with 500 Internal Server Error */
282282
httpd_json_resp_send(req, HTTPD_500, "Failed to write file to storage");
283-
return ESP_FAIL;
283+
return ESP_OK;
284284
}
285285

286286
/* Keep track of remaining size of

0 commit comments

Comments
 (0)