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

add axios error handler that handles drf messages #324

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

paribaker
Copy link
Contributor

What this does

Add a description of what feature/page this PR intends to add or change.

Checklist

  • Todo 1
  • Todo 2
  • Todo 3

How to test

Add user steps to achieve desired functionality for this feature.

@paribaker paribaker temporarily deployed to tn-spa-bootstrapper-pr-324 July 19, 2024 12:45 Inactive
@paribaker paribaker temporarily deployed to tn-spa-bootstrapper-pr-324 July 19, 2024 12:49 Inactive
@paribaker paribaker temporarily deployed to tn-spa-bootstrapper-pr-324 July 19, 2024 12:59 Inactive
@@ -0,0 +1,23 @@
import { isAxiosError, AxiosError } from 'axios'

export function handleDRFAPIErrorsOrReThrow(error: AxiosError | Error): string[]{
Copy link
Member

Choose a reason for hiding this comment

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

I'd say error is unknown

Copy link
Member

Choose a reason for hiding this comment

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

AxiosError type is inferred by the isAxiosError assert function on it's own, no need to declare it at all

Comment on lines +5 to +7
const e: AxiosError = error

const { data } = (e as AxiosError)?.response ?? null
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to cast here. In neither of the two lines

}
return []
}
throw error as Error
Copy link
Member

Choose a reason for hiding this comment

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

Not sure whether the cast does anything at all here 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants