Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Show errors 500 and 400 on preview #639

Merged
merged 28 commits into from
Oct 12, 2021
Merged

Show errors 500 and 400 on preview #639

merged 28 commits into from
Oct 12, 2021

Conversation

Klochette
Copy link
Contributor

@Klochette Klochette commented Sep 23, 2021

Fixes

Fixes #622

Description

Handle errors 500 and 400 on preview with notistack.

Definition of Done

  • I followed the Arkhn Code Book (I swear!).
  • I have written tests for the code I added or updated.
  • I have updated the documentation according to my changes.
  • I have updated the deployment configuration if needed.

@Klochette Klochette requested review from tevariou, BPierrick, simonvadee and a team September 23, 2021 14:09
@Klochette Klochette linked an issue Sep 23, 2021 that may be closed by this pull request
1 task
@simonvadee simonvadee force-pushed the sv/use-hapi-fhir-validator branch from 29cd41b to 0ee5627 Compare September 24, 2021 12:39
Comment on lines 160 to 173
const errorKey = Object.keys(errors);
errorKey.forEach((key) => {
enqueueSnackbar(
t<string>("catchValidationErrorPrompt", {
query: errorField,
errorStatus: errorType,
errorKey: key,
errorText: errors[key as keyof typeof errors],
}),
{
variant: "error",
}
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest you use Object.entries instead of Object.keys, because of what you do in line 167 => accessing errors[key]

Suggested change
const errorKey = Object.keys(errors);
errorKey.forEach((key) => {
enqueueSnackbar(
t<string>("catchValidationErrorPrompt", {
query: errorField,
errorStatus: errorType,
errorKey: key,
errorText: errors[key as keyof typeof errors],
}),
{
variant: "error",
}
);
});
const errorEntries = Object.entries(errors);
errorEntries.forEach(([key, text]) => {
enqueueSnackbar(
t<string>("catchValidationErrorPrompt", {
query: errorField,
errorStatus: errorType,
errorKey: key,
errorText: text,
}),
{
variant: "error",
}
);
});

}
};
previewCreate();
}
}
};

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a small comment explaining what this useEffect does?

@simonvadee simonvadee force-pushed the sv/use-hapi-fhir-validator branch from fc65673 to 4f61fd4 Compare October 5, 2021 14:57
@simonvadee simonvadee force-pushed the sv/use-hapi-fhir-validator branch 4 times, most recently from 1c5e0e6 to 4f61fd4 Compare October 5, 2021 15:22
Base automatically changed from sv/use-hapi-fhir-validator to v4 October 5, 2021 16:01
@Klochette Klochette requested a review from BPierrick October 11, 2021 10:07

const handleError = useCallback(
(error: FetchBaseQueryError) => {
const typedError = 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 does this line do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nothing anymore, i forgot to delete it

);

const handleError = useCallback(
(error: FetchBaseQueryError) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Casting the error variable here doesn't raise any eslint error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it doesn't

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm I thought we were in a catch statement

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm I thought we were in a catch statement

setAlerts([
const handleValidationError = useCallback(
(
errors: ApiValidationError<unknown> | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
errors: ApiValidationError<unknown> | undefined,
errors?: ApiValidationError<unknown>,

Comment on lines 181 to 187
const handleValidationError = useCallback(
(
errors: ApiValidationError<unknown> | undefined,
errorType: number | "FETCH_ERROR" | "PARSING_ERROR" | "CUSTOM_ERROR",
errorField: string
) => {
if (errors) {
Copy link
Contributor

@BPierrick BPierrick Oct 11, 2021

Choose a reason for hiding this comment

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

Declaring your props this way should raise you an error for defining facultative arguments before required ones

You can prevent this like this :

Suggested change
const handleValidationError = useCallback(
(
errors: ApiValidationError<unknown> | undefined,
errorType: number | "FETCH_ERROR" | "PARSING_ERROR" | "CUSTOM_ERROR",
errorField: string
) => {
if (errors) {
const handleValidationError = useCallback(
({
errors?: ApiValidationError<unknown>,
errorType: number | "FETCH_ERROR" | "PARSING_ERROR" | "CUSTOM_ERROR",
errorField: string
}) => {
if (errors) {

Comment on lines 213 to 231
else if (typedError.status === "PARSING_ERROR") {
enqueueSnackbar(
t<string>("catchValidationErrorPrompt", {
query: typedError.status,
errorStatus: typedError.originalStatus.toString(),
errorText: typedError.error,
}),
{ variant: "error" }
);
} else if (
(typedError.status === "FETCH_ERROR" ||
typedError.status === "CUSTOM_ERROR") &&
typedError.data
) {
enqueueSnackbar(`${typedError.status} : ${typedError.data as string}`, {
variant: "error",
});
}
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This is facultative, but maybe using a switch statement on the typedError.status variable would be more elegant.


const explore = async () => {
try {
const exploration = await apiExploreCreate({
Copy link
Contributor

Choose a reason for hiding this comment

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

You are shadowing the exploration variable

export type OperationOutcomeIssue = {
severity: SeverityEnum;
severity: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

You definitely shouldn't have those changes in your PR. I guess the merge you made was not from the latest commit of v4 ?

river-schema.yml Outdated
Comment on lines 3436 to 3456
OperationOutcomeIssue:
type: object
properties:
severity:
type: string
code:
type: string
diagnostics:
type: string
location:
type: array
items:
type: string
expression:
type: string
required:
- code
- diagnostics
- expression
- location
- severity
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why this is here. From v4 branch, OperationOutcomeIssue type should already be described at line 3396 :

OperationOutcomeIssue:
      type: object
      properties:
        severity:
          $ref: '#/components/schemas/SeverityEnum'
        code:
          type: string
        diagnostics:
          type: string
        location:
          type: array
          items:
            type: string
        expression:
          type: string
      required:
      - code
      - diagnostics
      - expression
      - location
      - severity

Comment on lines 1 to 11
# name: test_inmemory_fhir_api_validate
<class 'dict'> {
'issue': <class 'list'> [
],
'resourceType': 'OperationOutcome',
'text': <class 'dict'> {
'div': '<p> it went fine bro </p>',
'status': 'generated',
},
}
---
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what is this doing here? @simonvadee @tevariou any idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

must be removed (remains from the merge I guess)

@Klochette Klochette requested a review from BPierrick October 11, 2021 13:24
@@ -300,7 +363,7 @@ const Preview = (): JSX.Element => {
<Alert
key={index}
className={classes.alert}
severity={issue.severity}
severity={issue.severity as Color}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue.severity should already be of type Color

@Klochette Klochette requested a review from BPierrick October 11, 2021 15:30
Copy link
Contributor

@BPierrick BPierrick left a comment

Choose a reason for hiding this comment

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

lgtm

);

const handleError = useCallback(
(error: FetchBaseQueryError) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm I thought we were in a catch statement

);

const handleError = useCallback(
(error: FetchBaseQueryError) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm I thought we were in a catch statement

Copy link
Contributor

@simonvadee simonvadee left a comment

Choose a reason for hiding this comment

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

some python files have been changes where the shouldn't: can you reset them to their version on v4 ? you can do:

git reset <commit hash> <filename>

to restore the correct version

Comment on lines 1 to 11
# name: test_inmemory_fhir_api_validate
<class 'dict'> {
'issue': <class 'list'> [
],
'resourceType': 'OperationOutcome',
'text': <class 'dict'> {
'div': '<p> it went fine bro </p>',
'status': 'generated',
},
}
---
Copy link
Contributor

Choose a reason for hiding this comment

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

must be removed (remains from the merge I guess)

@Klochette Klochette requested a review from simonvadee October 12, 2021 09:20
@Klochette
Copy link
Contributor Author

some python files have been changes where the shouldn't: can you reset them to their version on v4 ? you can do:

git reset <commit hash> <filename>

to restore the correct version

I think I did it correctly

Copy link
Contributor

@simonvadee simonvadee left a comment

Choose a reason for hiding this comment

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

use "squash" instead of rebase to avoid conflicts

@Klochette Klochette merged commit 39476cc into v4 Oct 12, 2021
@Klochette Klochette deleted the mc/app/showErrorsOnPreview branch October 12, 2021 16:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors 500 are not shown on preview
3 participants