Skip to content

Commit

Permalink
fix: error handling in validateStorageSubmission
Browse files Browse the repository at this point in the history
  • Loading branch information
wanlingt committed Nov 14, 2023
1 parent cf430b0 commit fa344a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/modules/myinfo/myinfo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export class MyInfoServiceClass {
})
return errAsync(new MyInfoHashDidNotMatchError())
}
return okAsync(new Set(comparedFieldIds))
return errAsync(new MyInfoHashDidNotMatchError())
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export const validateStorageSubmission = async (
next: NextFunction,
) => {
const formDef = req.formsg.formDef
let spcpSubmissionFailure: undefined | true

const logMeta = {
action: 'validateStorageSubmission',
Expand Down Expand Up @@ -460,8 +461,8 @@ export const validateStorageSubmission = async (
const { authType } = form
switch (authType) {
case FormAuthType.SGID_MyInfo:
case FormAuthType.MyInfo:
return extractMyInfoLoginJwt(req.cookies, authType)
case FormAuthType.MyInfo: {
const populatedForm = extractMyInfoLoginJwt(req.cookies, authType)
.andThen(MyInfoService.verifyLoginJwt)
.asyncAndThen(({ uinFin }) =>
MyInfoService.fetchMyInfoHashes(uinFin, form._id)
Expand All @@ -479,18 +480,18 @@ export const validateStorageSubmission = async (
),
)
.mapErr((error) => {
spcpSubmissionFailure = true
logger.error({
message: `Error verifying MyInfo${
authType === FormAuthType.SGID_MyInfo ? '(over SGID)' : ''
} hashes`,
meta: logMeta,
error,
})
const { statusCode, errorMessage } = mapRouteError(error)
return res.status(statusCode).json({
message: errorMessage,
})
return error
})
return populatedForm
}
default:
return ok<IPopulatedStorageFormWithResponsesAndHash, never>({
parsedResponses,
Expand All @@ -513,6 +514,7 @@ export const validateStorageSubmission = async (
})
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
message: 'Error saving responses in req.body',
spcpSubmissionFailure,
})
})
}
Expand Down

0 comments on commit fa344a7

Please sign in to comment.