improve server error display
This commit is contained in:
parent
885fb3fa5f
commit
787c4fc42d
58
src/index.js
58
src/index.js
@ -1,19 +1,36 @@
|
||||
// Handle keyboard input
|
||||
|
||||
const imageExtensions = ['gif','jpg','jpeg','png', 'webp'];
|
||||
const videoExtensions =['mpg', 'mp2', 'mpeg', 'mpe', 'mpv', 'mp4'];
|
||||
const audioExtensions =['mp3', 'ogg', 'wav', 'flac'];
|
||||
|
||||
|
||||
let statusLine = document.getElementById('status');
|
||||
|
||||
const mappings = new Map(JSON.parse(localStorage.getItem('mappings')) || []);
|
||||
|
||||
let statusLine = document.getElementById('status');
|
||||
// store for when done with sorting TODO display
|
||||
let initialContent = document.getElementById('current-file').innerHTML;
|
||||
|
||||
let history = [];
|
||||
|
||||
// get the path in which the images are located and can be loaded from, by appending to them to the stagingPath
|
||||
//
|
||||
// SERVER COMMUNICATION
|
||||
//
|
||||
|
||||
/**
|
||||
* Only show the server response text if its a 500 internal
|
||||
*/
|
||||
function showServerError(fname, status, text) {
|
||||
if (status == 500) {
|
||||
message = `in ${fname}: server returned ${status}: '${text}'`;
|
||||
else {
|
||||
message = `in ${fname}: server returned ${status}`;
|
||||
|
||||
}
|
||||
statusLine.innerHTML = message
|
||||
console.error(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the path in which the images are located and can be loaded from, by appending to them to the stagingPath
|
||||
*/
|
||||
let stagingPath = "";
|
||||
async function setStagingPath() {
|
||||
const response = await fetch("imgsort.php?action=getStagingPath");
|
||||
@ -21,13 +38,13 @@ async function setStagingPath() {
|
||||
stagingPath = await response.text();
|
||||
}
|
||||
else {
|
||||
statusLine.innerHTML = `getStagingPath: server returned ${response.status}`;
|
||||
console.error("Could not get stagingPath from server");
|
||||
console.error(response);
|
||||
showServerError("setStagingPath", response.status, text);
|
||||
}
|
||||
}
|
||||
|
||||
// list of files to be processed
|
||||
/**
|
||||
* list of files to be processed
|
||||
*/
|
||||
let fileList = [];
|
||||
async function setFileList() {
|
||||
const response = await fetch("imgsort.php?action=getFileList");
|
||||
@ -38,12 +55,15 @@ async function setFileList() {
|
||||
// fileList.sort();
|
||||
}
|
||||
else {
|
||||
statusLine.innerHTML = `getFileList: server returned ${response.status}: '${text}'`;
|
||||
console.error("Could not get fileList from server");
|
||||
console.error(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// RENDERING
|
||||
//
|
||||
|
||||
/*
|
||||
* Create button for each mapping
|
||||
*/
|
||||
@ -142,6 +162,10 @@ function preloadNextFile() {
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// LOGIC
|
||||
//
|
||||
|
||||
// set the currentFile variable according to currentFileIdx
|
||||
function setCurrentFile() {
|
||||
// if none set and
|
||||
@ -185,8 +209,7 @@ async function moveFile(directory) {
|
||||
preloadNextFile();
|
||||
}
|
||||
else {
|
||||
statusLine.innerHTML = `moveFile: server returned ${response.status}: '${text}'`;
|
||||
console.error(`moveFile: server returned ${response.status}: '${text}'`);
|
||||
showServerError("moveFile", response.status, text);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,8 +229,7 @@ async function undo() {
|
||||
setCurrentFile();
|
||||
}
|
||||
else {
|
||||
statusLine.innerHTML = `undo: server returned ${response.status}: '${text}'`;
|
||||
console.error(`undo: server returned ${response.status}: '${text}'`);
|
||||
showServerError("undo", response.status, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user