Skip to content

Commit

Permalink
Merge pull request #828 from opencb/TASK-5271
Browse files Browse the repository at this point in the history
TASK-5271 - Landpage login error
  • Loading branch information
jmjuanes authored Nov 16, 2023
2 parents bc072b0 + 990c233 commit d842765
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/core/utils-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class UtilsNew {
return "warning";
}

static isError(obj) {
return obj && Object.prototype.toString.call(obj) === "[object Error]";
}

static isUndefined(obj) {
return typeof obj === "undefined";
}
Expand Down
2 changes: 1 addition & 1 deletion src/webcomponents/commons/layouts/custom-welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default class CustomWelcome extends LitElement {
render() {
const welcomePage = this.getWelcomePageConfig();

if (!UtilsNew.isNotEmptyArray(this.opencgaSession.projects) ||
if (!UtilsNew.isNotEmptyArray(this.opencgaSession?.projects) ||
this.opencgaSession.projects.every(p => !UtilsNew.isNotEmptyArray(p.studies))) {
return html`
<div class="guard-page">
Expand Down
15 changes: 11 additions & 4 deletions src/webcomponents/user/user-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import {LitElement, html} from "lit";
import {RestResponse} from "../../core/clients/rest-response.js";
import LitUtils from "../commons/utils/lit-utils.js";
import NotificationUtils from "../commons/utils/notification-utils.js";
import UtilsNew from "../../core/utils-new.js";


export default class UserLogin extends LitElement {
Expand Down Expand Up @@ -74,11 +74,11 @@ export default class UserLogin extends LitElement {
this.requestUpdate(); // Remove errors
this.opencgaSession.opencgaClient.login(user, password)
.then(response => {
if (response instanceof RestResponse) {
if (response && !UtilsNew.isError(response)) {
if (response.getEvents?.("ERROR")?.length) {
NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_RESPONSE, response);
} else if (response) {
const token = response.getResult(0).token;
} else {
const token = response?.getResult?.(0)?.token;
const decoded = jwt_decode(token);
const dateExpired = new Date(decoded.exp * 1000);
const validTimeSessionId = moment(dateExpired, "YYYYMMDDHHmmss").format("D MMM YY HH:mm:ss");
Expand All @@ -92,7 +92,14 @@ export default class UserLogin extends LitElement {
message: `Welcome back, <b>${user}</b>. Your session is valid until ${validTimeSessionId}`,
});
}
} else if (response) {
// Sometimes response is an instance of an Error, for example when the connection is lost before submitting the login.
// In this case we will display the returned error instead of displaying a 'Generic Server Error' message.
// TODO: check why this error is not captured in the 'catch'
NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_RESPONSE, response);
} else {
// This is a very strange situation when the response object is empty.
// In this case, as we do not have any error message we need to use this generic server error message.
NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_ERROR, {
title: "Generic Server Error",
message: "Unexpected response format. Please check your host is up and running.",
Expand Down

0 comments on commit d842765

Please sign in to comment.