云服务器内容精选

  • 使用自定义错误码 自定义错误码创建完成后,可在脚本中使用。在脚本中,调用抛出错误信息的error函数I18nError('ErrorCodeName','变量1','变量2')。该函数中,输入参数为错误码名称“t__testErrorCode”和错误码信息中所携带的变量("val1"和"val2")。 创建脚本。 参考创建空白AstroZero脚本中操作,创建一个空白脚本。 在脚本编辑器中,输入如下代码。 // test custom error func , get diff language error by user langimport * as error from 'error';export class TestDemo { @action.method({ label: 'test', description: 'error code', input: 'No input', output: 'No output' }) public test() { //使用I18nError函数设定错误码和错误码信息携带变量 throw new error.I18nError('t__testErrorCode', ["val1", "val2"]); }} 其中,“t__testErrorCode”为自定义错误码名称,请根据实际情况配置。 单击,保存脚本后,单击,启用脚本。 按照定义API接口中操作,绑定上述开发的脚本,进行测试。 图3 自定义错误信息测试