UNPKG

@hsui/sdk

Version:

Hundsun frontend framework JSSDK

24 lines 802 B
var errors = { INVALID_KEY: 'invalid ${ key }', INVALID_PARAMETERS: 'invalid parameters', INVALID_REQUEST: 'invalid request', INVALID_SDK_CALL: 'invalid sdk call ${ method }', NOT_FOUND: '${ key } not found', UNKNOWN_ERROR: 'unknown error' }; export function runningError() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'UNKNOWN_ERROR'; var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (errors.hasOwnProperty(type)) { return tpl(errors[type])(payload); } return tpl(errors['UNKNOWN_ERROR'])(payload); } function tpl(string) { return function (params) { Object.keys(params).forEach(function (key) { string = string.replace('${ ' + key + ' }', params[key]); }); return string; }; }