Skip to content

Latest commit

 

History

History
82 lines (68 loc) · 3.59 KB

throw.md

File metadata and controls

82 lines (68 loc) · 3.59 KB

try catch

Open in playground

export const main = asl.deploy.asStateMachine(async (input: Input) => 
 {
  try {
    throw new NotImplemented("not implemented")
  } catch (err) {
    if (err.Cause === "NotImplemented") {
      return "Todo"
    }
  }
});

throw errors

Open in playground

export const main = asl.deploy.asStateMachine(async (input: Input) => 
 {
  if (input.delayInSeconds > 10 || input.delayInSeconds < 1) {
    throw new ValidationError("delay in seconds must be numeric value no greater than 10 and no smaller than 1")
  }

  throw new NotImplemented("not implemented")
});

retry errors

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  asl.parallel({
    branches: [() => {
      throw new RetryableError("retry me")
    }],
    retry: [{
      errorEquals: ["RetryableError"],
      backoffRate: 1.5,
      intervalSeconds: 3,
      maxAttempts: 2
    }]
  })
});

catch errors

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  asl.parallel({
    branches: [() => {
      throw new UnexpectedError("bad luck!")
    }],
    retry: [{
      errorEquals: ["RetryableError"],
      backoffRate: 1.5,
      intervalSeconds: 3,
      maxAttempts: 2
    }],
    catch: [{
      errorEquals: ["UnexpectedError"],
      block: (error) => {
        console.log(`cause ${error.Cause}`)
        console.log(`message ${error.Error}`)
      }
    }]
  })
});