Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DT-841]Display error from Consent on Sign In #2701

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DEVNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Ensure that your `/etc/hosts` file has an entry for `local.dsde-dev.broadinstitu
127.0.0.1 local.dsde-dev.broadinstitute.org
```

Download cert files from dev project (requires access to correct project - see [DUOS team members](https://github.com/orgs/DataBiosphere/teams/duos) for more specifics). Cert files are regenerated on a 3-month rotation so these will need to be updated when they are expired:
Download cert files from dev project (requires access to correct project - see [DUOS team members](https://github.com/orgs/DataBiosphere/teams/duos) for more specifics). Cert files are regenerated on a 3-month rotation so these will need to be updated when they are expired. The following commands need to be done on the Broad VPN.
```shell
gcloud container clusters get-credentials --zone us-central1-a --project <project> terra-dev
kubectl -n local-dev get secrets local-dev-cert -o 'go-template={{ index .data "tls.crt" | base64decode }}' > server.crt
Expand All @@ -44,6 +44,7 @@ HTTPS=true
SSL_CRT_FILE=server.crt
SSL_KEY_FILE=server.key
```
Ensure that HOST is not set in your shell environment, as it will override the value in `.env.local`.

4. Start development server:

Expand Down
11 changes: 0 additions & 11 deletions src/components/Alert.jsx

This file was deleted.

24 changes: 24 additions & 0 deletions src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import './Alert.css';
import CloseIcon from '@mui/icons-material/Close';

export interface AlertProps {
id: string;
type: string;
title: string;
description: string;
onClose?: () => void;
}

export const Alert = (props: AlertProps) => {
const {id, type, title, description, onClose} = props;
return (
<div id={`${id}_alert`} className={`alert-wrapper ${type}`} style={{border: '1px solid red', borderRadius: '5px'}}>
{onClose && <span
style={{float: 'right', fontWeight: 'bolder', fontSize: 24, cursor: 'pointer'}}
onClick={onClose} ><CloseIcon/></span> }
{title && <h4 id={`${id}_title`} className="alert-title">{title}</h4>}
{description && <span id={`${id}_description`} className="alert-description">{description}</span>}
</div>
);
};
29 changes: 19 additions & 10 deletions src/components/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ErrorDisplay = ErrorInfo | React.JSX.Element;

interface HttpError extends Error {
status?: number;
body?: ReadableStream<Uint8Array>;
}

export const SignInButton = (props: SignInButtonProps) => {
Expand Down Expand Up @@ -113,18 +114,31 @@ export const SignInButton = (props: SignInButtonProps) => {
await Metrics.captureEvent(event);
};

const errorStreamToString = async (error: HttpError) => {
const body = await new Response(error.body).json();
return body.message || JSON.stringify(body);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is a message return that, else return the whole error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if that is really long? Do we truncate the message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe its truncated, I think it will display the whole thing. Would it be preferable to truncate it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. This is possibly something we can just observe and address if it becomes a problem.

};

const handleServerError = async (error: HttpError) => {
const errorMessage = await errorStreamToString(error);
setErrorDisplay({show: true, title: 'Error', description: errorMessage});
};

const handleErrors = async (error: HttpError, redirectTo: string, shouldRedirect: boolean) => {
const status = error.status;

switch (status) {
case 400:
setErrorDisplay({show: true, title: 'Error', msg: JSON.stringify(error)});
setErrorDisplay({show: true, title: 'Error', description: JSON.stringify(error)});
break;
case 409:
await handleConflictError(redirectTo, shouldRedirect);
break;
case 500:
await handleServerError(error);
break;
default:
setErrorDisplay({show: true, title: 'Error', msg: 'Unexpected error, please try again'});
setErrorDisplay({show: true, title: 'Error', description: 'Unexpected error, please try again'});
break;
}
};
Expand All @@ -143,14 +157,8 @@ export const SignInButton = (props: SignInButtonProps) => {
if (response.toString().includes('Popup closed by user')) {
setErrorDisplay(
{title: 'Sign in cancelled', description: 'Sign in cancelled by closing the sign in window'});
setTimeout(() => {
setErrorDisplay({});
}, 2000);
} else {
setErrorDisplay({title: 'Error', description: response.toString()});
setTimeout(() => {
setErrorDisplay({});
}, 2000);
}
};

Expand Down Expand Up @@ -205,8 +213,9 @@ export const SignInButton = (props: SignInButtonProps) => {
<Alert
id="dialog"
type="danger"
title={(errorDisplay as ErrorInfo).title}
description={(errorDisplay as ErrorInfo).description}
title={(errorDisplay as ErrorInfo).title || 'Error'}
description={(errorDisplay as ErrorInfo).description || ''}
onClose={() => setErrorDisplay({})}
/>
</div>
}
Expand Down
Loading