當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript errorHandling.ErrorHandling類代碼示例

本文整理匯總了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;未經允許,請勿轉載。