| 12345678910111213141516171819202122232425262728293031 |
- /** 语句:try:须含 try、success、fail 三个数组(可为 []);可选 continueAfterFail */
- const { assertStrictKeys } = require('../action-schema.js')
- const types = ['try']
- function parse (action, parseContext) {
- const path = parseContext.actionPath || 'try'
- assertStrictKeys(action, ['type', 'try', 'success', 'fail', 'continueAfterFail'], path)
- if (!Array.isArray(action.try)) {
- throw new Error(`${path}: try 须包含数组 try`)
- }
- if (!Array.isArray(action.success)) {
- throw new Error(`${path}: try 须包含数组 success(无成功后续写 [])`)
- }
- if (!Array.isArray(action.fail)) {
- throw new Error(`${path}: try 须包含数组 fail(无失败处理写 [])`)
- }
- const out = {
- type: 'try',
- try: parseContext.parseActions(action.try, 'try'),
- success: parseContext.parseActions(action.success, 'success'),
- fail: parseContext.parseActions(action.fail, 'fail'),
- }
- if (action.continueAfterFail === true) out.continueAfterFail = true
- return out
- }
- async function execute() {
- return { success: true }
- }
- module.exports = { types, parse, execute }
|