本文整理匯總了TypeScript中shared/errorHandling.ErrorHandling類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ErrorHandling類的具體用法?TypeScript ErrorHandling怎麽用?TypeScript ErrorHandling使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ErrorHandling類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: buildRouter
buildRouter (): express.Router {
return express.Router()
.get(Paths.repaymentPlanPage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
const draft: Draft<DraftCCJ> = res.locals.ccjDraft
this.renderView(new Form(draft.document.repaymentPlan), res)
}))
.post(Paths.repaymentPlanPage.uri,
FormValidator.requestHandler(RepaymentPlan, RepaymentPlan.fromObject),
ErrorHandling.apply(
async (req: express.Request, res: express.Response): Promise<void> => {
let form: Form<PaidAmount> = req.body
const error: FormValidationError = this.postValidation(req, res)
if (error) {
form = new Form<PaidAmount>(form.model, [error, ...form.errors])
}
if (form.hasErrors()) {
this.renderView(form, res)
} else {
res.locals.draft.document.repaymentPlan = form.model
res.locals.draft.document.payBySetDate = undefined
await this.saveDraft(res.locals)
res.redirect(this.buildPostSubmissionUri(req, res))
}
})
)
}
示例2: buildRouter
buildRouter (): express.Router {
return express.Router()
.get(this.path.uri, (req: express.Request, res: express.Response): void => {
this.renderView(new Form(eligibilityStore.read(req, res)), res)
})
.post(this.path.uri,
FormValidator.requestHandler(undefined, Eligibility.fromObject, this.property),
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
const form: Form<Eligibility> = req.body
if (form.hasErrors()) {
this.renderView(form, res)
} else {
let eligibility: Eligibility = eligibilityStore.read(req, res)
if (eligibility === undefined) {
eligibility = new Eligibility()
}
eligibility[this.property] = form.model[this.property]
eligibilityStore.write(eligibility, req, res)
this.handleAnswer(eligibility[this.property], res)
}
})
)
}
示例3: buildRouter
buildRouter (path: string, ...guards: express.RequestHandler[]): express.Router {
const stateGuardRequestHandler: express.RequestHandler = GuardFactory.create((res: express.Response): boolean => {
const model: PaymentIntention = this.createModelAccessor().get(res.locals.draft.document)
return model
&& model.paymentOption
&& model.paymentOption.isOfType(PaymentType.INSTALMENTS)
}, (req: express.Request, res: express.Response): void => {
throw new NotFoundError(req.path)
})
return express.Router()
.get(path + Paths.paymentPlanPage.uri,
...guards,
stateGuardRequestHandler,
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
this.renderView(new Form(this.createModelAccessor().get(res.locals.draft.document).paymentPlan), res)
}))
.post(path + Paths.paymentPlanPage.uri,
...guards,
stateGuardRequestHandler,
FormValidator.requestHandler(PaymentPlanModel, PaymentPlanModel.fromObject, undefined, ['calculatePaymentPlan']),
ErrorHandling.apply(
async (req: express.Request, res: express.Response): Promise<void> => {
let form: Form<PaymentPlanModel> = req.body
const error: FormValidationError = this.postValidation(req, res)
if (error) {
form = new Form<PaymentPlanModel>(form.model, [error, ...form.errors])
}
if (form.hasErrors() || _.get(req, 'body.action.calculatePaymentPlan')) {
this.renderView(form, res)
} else {
this.createModelAccessor().patch(res.locals.draft.document, model => model.paymentPlan = form.model)
await this.saveDraft(res.locals)
res.redirect(this.buildPostSubmissionUri(req, res))
}
}))
}
示例4: buildRouter
buildRouter (path: string, ...guards: express.RequestHandler[]): express.Router {
const stateGuardRequestHandler: express.RequestHandler = GuardFactory.create((res: express.Response): boolean => {
const model: PaymentIntention = this.createModelAccessor().get(res.locals.draft.document)
return model && model.paymentOption && model.paymentOption.isOfType(PaymentType.BY_SET_DATE)
}, (req: express.Request): void => {
throw new NotFoundError(req.path)
})
return express.Router()
.get(
path + Paths.paymentDatePage.uri,
...guards,
stateGuardRequestHandler,
(req: express.Request, res: express.Response) => {
this.renderView(new Form(this.createModelAccessor().get(res.locals.draft.document).paymentDate), res)
})
.post(
path + Paths.paymentDatePage.uri,
...guards,
stateGuardRequestHandler,
FormValidator.requestHandler(PaymentDate, PaymentDate.fromObject),
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
const form: Form<PaymentDate> = req.body
if (form.hasErrors()) {
this.renderView(form, res)
} else {
this.createModelAccessor().patch(res.locals.draft.document, model => model.paymentDate = form.model)
await this.saveDraft(res.locals)
res.redirect(this.buildPostSubmissionUri(req, res))
}
}))
}
示例5: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
const form: Form<Dependants> = req.body
if (form.hasErrors()) {
res.render(page.associatedView, { form: form })
} else {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
const user: User = res.locals.user
draft.document.statementOfMeans.dependants = form.model
// skip if defendant and partner are both disabled, or if defendant is severely disabled
const defendantIsDisabled: boolean = draft.document.statementOfMeans.disability.option === DisabilityOption.YES
const defendantIsSeverelyDisabled: boolean = draft.document.statementOfMeans.severeDisability
&& draft.document.statementOfMeans.severeDisability.option === SevereDisabilityOption.YES
const partnerIsDisabled: boolean = draft.document.statementOfMeans.cohabiting.option === CohabitingOption.YES
&& draft.document.statementOfMeans.partnerDisability.option === PartnerDisabilityOption.YES
// also skip if there aren't any children
const hasChildren: boolean = form.model.numberOfChildren && totalNumberOfChildren(form.model) > 0
const skipDisabilityQuestion: boolean = !hasChildren || (defendantIsDisabled && partnerIsDisabled) || defendantIsSeverelyDisabled
if (!form.model.numberOfChildren || !form.model.numberOfChildren.between16and19) {
draft.document.statementOfMeans.education = undefined
}
if (skipDisabilityQuestion) {
draft.document.statementOfMeans.dependantsDisability = undefined
}
await new DraftService().save(draft, user.bearerToken)
const { externalId } = req.params
if (form.model.numberOfChildren && form.model.numberOfChildren.between16and19) {
res.redirect(Paths.educationPage.evaluateUri({ externalId: externalId }))
} else if (skipDisabilityQuestion) {
res.redirect(Paths.otherDependantsPage.evaluateUri({ externalId: externalId }))
} else {
res.redirect(Paths.dependantsDisabilityPage.evaluateUri({ externalId: externalId }))
}
}
})
示例6: Form
.get(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
stateGuardRequestHandler,
(req: express.Request, res: express.Response) => {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
res.render(page.associatedView, { form: new Form(draft.document.statementOfMeans.onTaxPayments) })
})
.post(
page.uri,
StatementOfMeansStateGuard.requestHandler(),
stateGuardRequestHandler,
FormValidator.requestHandler(OnTaxPayments, OnTaxPayments.fromObject),
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
const form: Form<OnTaxPayments> = req.body
if (form.hasErrors()) {
res.render(page.associatedView, { form: form })
} else {
const draft: Draft<ResponseDraft> = res.locals.responseDraft
const user: User = res.locals.user
draft.document.statementOfMeans.onTaxPayments = form.model
await new DraftService().save(draft, user.bearerToken)
const { externalId } = req.params
res.redirect(StatementOfMeansPaths.courtOrdersPage.evaluateUri({ externalId: externalId }))
}
})
)
示例7: renderView
res.redirect(DashboardPaths.claimantPage.evaluateUri({ externalId: claim.externalId }))
} else {
res.render(Paths.responsePage.associatedView, {
form: form,
claim: claim,
offer: offer
})
}
}
/* tslint:disable:no-default-export */
export default express.Router()
.get(
Paths.responsePage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
renderView(Form.empty(), res, next)
}))
.post(
Paths.responsePage.uri,
FormValidator.requestHandler(DefendantResponse, DefendantResponse.fromObject),
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
const form: Form<DefendantResponse> = req.body
if (form.hasErrors()) {
renderView(form, res, next)
} else {
const claim: Claim = res.locals.claim
const user: User = res.locals.user
switch (form.model.option) {
case StatementType.ACCEPTATION:
res.redirect(Paths.makeAgreementPage.evaluateUri({ externalId: claim.externalId }))
break
示例8:
import * as express from 'express'
import { Paths } from 'offer/paths'
import { ErrorHandling } from 'shared/errorHandling'
import { Claim } from 'claims/models/claim'
/* tslint:disable:no-default-export */
export default express.Router()
.get(
Paths.rejectedPage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const claim: Claim = res.locals.claim
res.render(Paths.rejectedPage.associatedView, {
claim: claim
})
}))
示例9: DraftService
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const form: Form<HearingLocation> = req.body
if (form.hasErrors()) {
renderPage(res, form, false)
} else {
try {
const draft: Draft<DirectionsQuestionnaireDraft> = res.locals.draft
const user: User = res.locals.user
if (form.model.courtAccepted === YesNoOption.NO && form.model.alternativeOption === AlternativeCourtOption.BY_POSTCODE) {
const court: Court = await getNearestCourt(form.model.alternativePostcode)
if (court !== undefined) {
form.model = new HearingLocation(court.name, form.model.alternativePostcode)
}
renderPage(res, form, court === undefined)
} else {
if (form.model.courtAccepted === undefined) {
draft.document.hearingLocation = form.model.alternativeCourtName
} else {
draft.document.hearingLocation = form.model.courtName
}
await new DraftService().save(draft, user.bearerToken)
res.redirect(Paths.expertPage.evaluateUri({ externalId: res.locals.claim.externalId }))
}
} catch (err) {
next(err)
}
}
}))
示例10: renderView
import { FormValidator } from 'forms/validation/formValidator'
import { ClaimReference } from 'forms/models/claimReference'
import { isCMCReference } from 'shared/utils/isCMCReference'
import { Form } from 'forms/form'
function renderView (form: Form<ClaimReference>, res: express.Response): void {
res.render(Paths.enterClaimNumberPage.associatedView, { form: form })
}
const mcolUrl = config.get<string>('mcol.url')
/* tslint:disable:no-default-export */
export default express.Router()
.get(Paths.enterClaimNumberPage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
renderView(Form.empty<ClaimReference>(), res)
})
)
.post(
Paths.enterClaimNumberPage.uri,
FormValidator.requestHandler(ClaimReference),
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
const form: Form<ClaimReference> = req.body
if (form.hasErrors()) {
renderView(form, res)
} else {
if (isCMCReference(form.model.reference)) {
res.redirect(Paths.homePage.uri)
} else {
res.redirect(mcolUrl)