Skip to content

Commit

Permalink
[DT-841]Display error from Consent on Sign In (#2701)
Browse files Browse the repository at this point in the history
Co-authored-by: rjohanek <[email protected]>
  • Loading branch information
rjohanek and raejohanek authored Oct 31, 2024
1 parent 358b65c commit 0a1aba2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
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);
};

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

0 comments on commit 0a1aba2

Please sign in to comment.