• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript errorHandling.ErrorHandling类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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))
            }
          })
      )
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:32,代码来源:repayment-plan.ts


示例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)
          }
        })
      )
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:26,代码来源:eligibilityPage.ts


示例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))
            }
          }))
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:43,代码来源:payment-plan.ts


示例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))
          }
        }))
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:36,代码来源:payment-date.ts


示例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 }))
        }
      }
    })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:40,代码来源:dependants.ts


示例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 }))
      }
    })
  )
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:30,代码来源:on-tax-payments.ts


示例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
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:response.ts


示例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
      })
    }))
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:15,代码来源:rejected.ts


示例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)
        }
      }
    }))
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:33,代码来源:hearing-location.ts


示例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)
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:enter-claim-number.ts



注:本文中的shared/errorHandling.ErrorHandling类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript helpers.getDocumentId函数代码示例发布时间:2022-05-25
下一篇:
TypeScript paymentOption.PaymentOption类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap