-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat(api error): backend API error handling #70
feat(api error): backend API error handling #70
Conversation
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fine to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic is becoming too complicated now - convert to RTK Query and save a lot of effort
@@ -101,10 +101,10 @@ export const VerifyRegistration = ({ | |||
} | |||
|
|||
const hasRoles = () => { | |||
return true | |||
return registrationData.companyRoles.length > 0 | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also remove the { return * }
const hasRoles = () => registrationData.companyRoles.length > 0
} | ||
const hasDocuments = () => { | ||
return documents && documents.length > 0 ? true : false | ||
return documents && documents.length > 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write as
const hasDocuments = () => documents && documents.length > 0
default: | ||
return t('ErrorMessage.defaultReload') | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too complicated. write simply as:
const getErrorMessage = (errorCode: number) => t(\
ErrorMessage.${errorCode}`
and then add descriptions in the jsons like
"ErrorMessage": {
"400": "...",
"401": "...",
etc.
@@ -76,7 +76,7 @@ export const CompanyDataCax = ({ | |||
const applicationId = obj['applicationId'] | |||
|
|||
useEffect(() => { | |||
dispatch(getCompanyDetailsWithAddress(applicationId)) | |||
dispatch(getCompanyDetailsWithAddress({applicationId, dispatch})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the old way to do api calls - also it is considered bad practice to call dispatch from a Redux action. See answers in https://stackoverflow.com/a/41260990/830067
convert the redux code to the new apiSlice way as has been done in the portal frontend and then use
const { data, error } = useGetCompanyDetailsWithAddressQuery(applicationId)
outside of the useEffect. We can also handle the error here instead of the unnecessary statusCodeError.ts
@@ -61,13 +62,15 @@ const updateStatus = createAsyncThunk( | |||
|
|||
const getCompanyDetailsWithAddress = createAsyncThunk( | |||
`${name}/companyDetailsWithAddress/get`, | |||
async (applicationId: string) => { | |||
async ({applicationId, dispatch}: {applicationId: string, dispatch: Dispatch}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as written in the other comment convert this to an RTK Query apiSlice and don't use dispatch inside another redux reducer. We can then handle the error outside of the Redux code as shown in another comment
export const statusCodeSelector = (state: RootState): number => | ||
state.statuscode.errorCode | ||
|
||
export default slice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file because we can handle errors the RTK Query way
return await ApplicationApi.getInstance().getCompanyDetailsWithAddress( | ||
applicationId | ||
) | ||
} catch (error: unknown) { | ||
} catch (error: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use try { ... } catch (error: any) {...}
here - instead convert this into a RTK Query apiSlice with built in error handling
Description
Backend API Error handling according to status code
Why
UI Improvementts
Issue
n/a
Checklist
Please delete options that are not relevant.