Skip to content

Commit

Permalink
fix(public-form/controller): fixed regression issues where certain fi…
Browse files Browse the repository at this point in the history
…elds were missed
  • Loading branch information
seaerchin committed Apr 12, 2021
1 parent 94d1a25 commit 0ae0623
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/app/modules/form/public-form/public-form.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import querystring from 'querystring'
import { UnreachableCaseError } from 'ts-essentials'

import { AuthType } from '../../../../types'
import { ErrorDto } from '../../../../types/api'
import { ErrorDto, PrivateFormErrorDto } from '../../../../types/api'
import { createLoggerWithLabel } from '../../../config/logger'
import { isMongoError } from '../../../utils/handle-mongo-error'
import { createReqMeta, getRequestIp } from '../../../utils/request'
Expand Down Expand Up @@ -188,7 +188,7 @@ export const handleRedirect: RequestHandler<
*/
export const handleGetPublicForm: RequestHandler<
{ formId: string },
PublicFormViewDto | ErrorDto
PublicFormViewDto | ErrorDto | PrivateFormErrorDto
> = async (req, res) => {
const { formId } = req.params
const logMeta = {
Expand All @@ -214,6 +214,19 @@ export const handleGetPublicForm: RequestHandler<
})
}
const { errorMessage, statusCode } = mapRouteError(error)

// Specialized error response for PrivateFormError.
// This is to maintain backwards compatibility with the middleware implementation
if (error instanceof PrivateFormError) {
return res.status(statusCode).json({
message: error.message,
// Flag to prevent default 404 subtext ("please check link") from
// showing.
isPageFound: true,
formTitle: error.formTitle,
})
}

return res.status(statusCode).json({ message: errorMessage })
}

Expand Down
7 changes: 6 additions & 1 deletion src/types/api/core.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type ErrorDto = {
export interface ErrorDto {
message: string
}

export interface PrivateFormErrorDto extends ErrorDto {
isPageFound: true
formTitle: string
}

0 comments on commit 0ae0623

Please sign in to comment.