Skip to content

Commit

Permalink
Improve the "time difference" error message
Browse files Browse the repository at this point in the history
  • Loading branch information
nirui committed Mar 6, 2024
1 parent 152c970 commit ae7e1a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
6 changes: 5 additions & 1 deletion ui/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
}

body.app-error {
background: #b44;
background: #944;
color: #fff;
}

body.app-error .app-error-message {
white-space: pre-line;
}

#app-loading {
width: 100%;
min-height: 100%;
Expand Down
31 changes: 22 additions & 9 deletions ui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const mainTemplate = `
:error="authErr"
@auth="submitAuth"
></auth>
<loading v-else :error="loadErr"></loading>
<loading class="app-error-message" v-else :error="loadErr"></loading>
`.trim();

const socksInterface = "/sshwifty/socket";
Expand Down Expand Up @@ -288,17 +288,30 @@ function startApp(rootEl) {
let result = await this.doAuth("");

if (result.date) {
let serverTime = result.date.getTime(),
clientTime = new Date().getTime(),
timeDiff = Math.abs(serverTime - clientTime);
let serverRespondTime = result.date,
serverRespondTimestamp = serverRespondTime.getTime(),
clientCurrent = new Date(),
clientTimestamp = clientCurrent.getTime(),
timeDiff = Math.abs(serverRespondTimestamp - clientTimestamp);

if (timeDiff > maxTimeDiff) {
this.loadErr =
"The time difference between this client " +
"and the backend server is beyond operational limit.\r\n\r\n" +
"Please try reload the page, and if the problem persisted, " +
"consider to adjust your local time so both the client and " +
"the server are running at same date time";
"The datetime difference between current client " +
"and the Sshwifty server is beyond the operational tolerance." +
"\r\n\r\n" +
"The server time was " +
serverRespondTime +
", and the client time was " +
clientCurrent +
", resulted a " +
timeDiff +
"ms time difference, exceeding the " +
"limitation of " +
maxTimeDiff +
"ms.\r\n\r\n" +
"Try reload the page, see if the problem persists. And if " +
"it did, please make sure both the server and the client are " +
"having the correct time settings";

return;
}
Expand Down

0 comments on commit ae7e1a7

Please sign in to comment.