Skip to content

Commit

Permalink
Add 401 and 403 error messages for put saver
Browse files Browse the repository at this point in the history
Show the user a slightly more useful message for the case where
they're not correctly authenticated and try to do a "put" save.

(I'm thinking about TiddlyHost, but it should be generally useful.)

WIP. Not sure what to do with the translations. Is it better to
leave them out entirely? Will it fallback to en-GB automatically? Is
there some other standard way to add a placeholder? Should I try
filling them in with Google Translate?
  • Loading branch information
simonbaird committed Apr 25, 2021
1 parent ac15334 commit d161032
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/language/en-GB/Misc.multids
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ Error/EditConflict: File changed on server
Error/Filter: Filter error
Error/FilterSyntax: Syntax error in filter expression
Error/FilterRunPrefix: Filter Error: Unknown prefix for filter run
Error/Forbidden: Permission denied
Error/IsFilterOperator: Filter Error: Unknown operand for the 'is' filter operator
Error/FormatFilterOperator: Filter Error: Unknown suffix for the 'format' filter operator
Error/LoadingPluginLibrary: Error loading plugin library
Error/NetworkErrorAlert: `<h2>''Network Error''</h2>It looks like the connection to the server has been lost. This may indicate a problem with your network connection. Please attempt to restore network connectivity before continuing.<br><br>''Any unsaved changes will be automatically synchronised when connectivity is restored''.`
Error/RecursiveTransclusion: Recursive transclusion error in transclude widget
Error/RetrievingSkinny: Error retrieving skinny tiddler list
Error/SavingToTWEdit: Error saving to TWEdit
Error/Unauthorized: Authentication required
Error/WhileSaving: Error while saving
Error/XMLHttpRequest: XMLHttpRequest error code
InternalJavaScriptError/Title: Internal JavaScript Error
Expand Down
7 changes: 5 additions & 2 deletions core/modules/savers/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ PutSaver.prototype.save = function(text,method,callback) {
// response is textual: "XMLHttpRequest error code: 412"
var status = Number(err.substring(err.indexOf(':') + 2, err.length))
if(status === 412) { // edit conflict
var message = $tw.language.getString("Error/EditConflict");
callback(message);
callback($tw.language.getString("Error/EditConflict"));
} else if(status === 401) { // authentication required
callback($tw.language.getString("Error/Unauthorized"));
} else if(status === 403) { // permission denied
callback($tw.language.getString("Error/Forbidden"));
} else {
callback(err); // fail
}
Expand Down

0 comments on commit d161032

Please sign in to comment.