Skip to content

Commit

Permalink
fix: add error management to socket - Ref gestion-de-projet#2469
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi-BOUYAHIA committed Jul 4, 2024
1 parent fdbb514 commit 6037d92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/components/CreationCohort/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const ControlPanel: React.FC<{
const { uuid, includePatient, status, jobFailMsg } = count

const [patientCount, setPatientCount] = useState(includePatient)
const [countError, setCountError] = useState<string | undefined>(jobFailMsg)
const [countStatus, setCountStatus] = useState<string | undefined>(status)

const [requestShare, setRequestShare] = useState<RequestType | null>({
currentSnapshot,
Expand Down Expand Up @@ -220,7 +222,9 @@ const ControlPanel: React.FC<{
setCountLoading(LoadingStatus.FETCHING)
dispatch(countCohortCreation({ uuid: uuid }))
}
}, [dispatch, status, uuid])
setCountStatus(status)
setCountError(jobFailMsg)
}, [dispatch, status, uuid, jobFailMsg])

useEffect(() => {
setPatientCount(includePatient)
Expand All @@ -236,6 +240,12 @@ const ControlPanel: React.FC<{
setPatientCount(message.extra_info?.measure)
setCountLoading(LoadingStatus.SUCCESS)
}
if (message.job_name === WebSocketJobName.COUNT && message.status === WebSocketJobStatus.failed) {
setCountStatus('failed')
setPatientCount(message.extra_info?.measure)
setCountError(message.extra_info?.request_job_fail_msg)
setCountLoading(LoadingStatus.SUCCESS)
}
}

webSocketContext?.addListener(listener)
Expand Down Expand Up @@ -408,11 +418,11 @@ const ControlPanel: React.FC<{
</Button>
</Alert>
)}
{(status === 'failed' || status === 'error') && (
{(countStatus === 'failed' || countStatus === 'error') && (
<Alert className={classes.errorAlert} severity="error">
Une erreur est survenue lors du calcul du nombre de patients de votre requête.
<br />
<Typography style={{ wordBreak: 'break-all' }}>{jobFailMsg}</Typography>
<Typography style={{ wordBreak: 'break-all' }}>{countError}</Typography>
<br />
<Button
onClick={() => _relaunchCount(false)}
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export enum WebSocketJobStatus {
pending = 'pending',
suspended = 'suspended',
accepted = 'accepted',
finished = 'finished'
finished = 'finished',
failed = 'failed'
}

export enum CohortJobStatus {
Expand Down Expand Up @@ -904,6 +905,7 @@ export type WebSocketMessage = {
job_name?: WebSocketJobName
extra_info?: {
fhir_group_id?: string
request_job_fail_msg?: string
request_job_status: JobStatus
measure?: number
global?: { measure_min: number; measure_max: number }
Expand Down

0 comments on commit 6037d92

Please sign in to comment.