Skip to content

Commit

Permalink
Show error message when uploading fails (#14349)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner authored Oct 24, 2024
1 parent 0c5f694 commit e8e2e92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/filesystem/src/browser/file-upload-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class FileUploadService {
} catch (error) {
uploadSemaphore.cancel();
if (!isCancelled(error)) {
this.messageService.error(nls.localize('theia/filesystem/uploadFailed', 'An error occurred while uploading a file. {0}', error.message));
throw error;
}
}
Expand Down Expand Up @@ -348,6 +349,10 @@ export class FileUploadService {
unregister();
if (xhr.status === 200) {
resolve();
} else if (xhr.status === 500 && xhr.statusText !== xhr.response) {
// internal error with cause message
// see packages/filesystem/src/node/node-file-upload-service.ts
reject(new Error(`Internal server error: ${xhr.response}`));
} else {
reject(new Error(`POST request failed: ${xhr.status} ${xhr.statusText}`));
}
Expand Down
8 changes: 7 additions & 1 deletion packages/filesystem/src/node/node-file-upload-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ export class NodeFileUploadService implements BackendApplicationContribution {
response.status(200).send(target); // ok
} catch (error) {
console.error(error);
response.sendStatus(500); // internal server error
if (error.message) {
// internal server error with error message as response
response.status(500).send(error.message);
} else {
// default internal server error
response.sendStatus(500);
}
}
}

Expand Down

0 comments on commit e8e2e92

Please sign in to comment.