• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.isError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中lodash.isError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isError函数的具体用法?TypeScript isError怎么用?TypeScript isError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isError函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: requestWithDefaults

        req = requestWithDefaults(url, options, (error: HttpError, response = resp, body?: any) => {
          // node.js assigns status string as body for status codes not having body data
          if (response && response.statusCode === 202) {
            diag.debug.assert(body === http.STATUS_CODES[202], body);
            body = undefined; // resolves promise to undefined below
          }

          // error processing
          if (!error && response && response.statusCode >= 400) {
            if (_.isError(body)) {
              // correct but practically impossible
              error = body;
            } else if (_.isString(body)) {
              // use plain-text as Error message
              error = new Error(body);
            } else if (_.isObjectLike(body)) {
              // body is object representation of server-side error or exception,
              // converting to true Error object here
              error = new Error(response.statusMessage);
              diag.debug.assert(() => !_.isArray(body),
                'kicks in for array responses as well, not sure if this is desirable');
              _.extend(error, body);
            } else {
              // handles numbers, booleans, etc. assigning as cause of failure
              error = new Error(response.statusMessage);
              if (!_.isUndefined(body)) {
                error.cause = body;
              }
            }
            // additional HttpError properties eventually set below
          }
          if (error) {
            // completes HttpError construction
            diag.debug.assertIsError(error, 'should operate true Error instances');
            error.requestUrl = url;
            if (response) {
              error.statusCode = response.statusCode;
              error.statusMessage = response.statusMessage;
              Object.defineProperty(error, 'rawResponse', {
                value: response,
                enumerable: false
              });
            }
            Object.defineProperty(error, 'rawRequest', {
              value: req,
              enumerable: false
            });
          }

          if (!response) {
            // network connectivity problem
            serverObj.serverInfos = null;
            diag.debug.assertIsError(error);
            if (promiseResponse) {
              rejectResponse(error); // will also rejectResult(error)
            } else {
              rejectResult(error); // promiseResponse not constructed yet
            }
          } else {
            // server information
            serverObj.serverInfos = {
              version: response.headers['x-relution-version'],
              description: response.headers['x-server']
            };
            if (response.statusCode === 503 ||
                response.statusCode === 500 && error.className === 'java.util.concurrent.TimeoutException') {
              // 503 (service unavailable) indicates the server is temporarily overloaded, and unable
              // handling the request. This happens when async delegation timed out on the Java side,
              // usually after about 2 minutes. In this case retry the request until we are done...
              diag.debug.info('server overloaded, retrying request.');
              // here promiseResponse must have been resolved already,
              // we chain anyways because of error propagation
              promiseResponse.thenResolve(ajax<T>(options)).done(resolveResult, rejectResult);
              return; // early exit as result is handled by done call above
            } else {
              // logon session processing
              let sessionUserUuid = response.headers['x-gofer-user'];
              if (sessionUserUuid) {
                serverObj.sessionUserUuid = sessionUserUuid;
              } else if (response.statusCode === 401) {
                // apparently our session is lost!
                serverObj.sessionUserUuid = null;
                diag.debug.assert(() => !!error);
                diag.debug.warn('server session is lost!', error);
                const credentials = serverObj.credentials;
                if (credentials) {
                  // recover by attempting login,
                  // here promiseResponse must have been resolved already,
                  // we chain anyways because of error propagation
                  serverObj.credentials = null;
                  promiseResponse.thenResolve(login(credentials, {
                    serverUrl: serverUrl
                  }).then(() => {
                    diag.debug.assert(() => !!serverObj.sessionUserUuid);
                    diag.debug.info('server session recovered.');
                    return ajax<T>(options);
                  })).done(resolveResult, rejectResult);
                  return; // early exit as result is handled by done call above
                }
              }
//.........这里部分代码省略.........
开发者ID:relution-io,项目名称:relution-sdk,代码行数:101,代码来源:http.ts


示例2: assert

 }).catch(function (e) {
   assert(_.isError(e));
   done();
 });
开发者ID:martinpinto,项目名称:cockroach,代码行数:4,代码来源:api.spec.ts


示例3: info

  info (msg: string) {
    this.msg(LogType.INFO, msg)
  },
  debug (msg: string) {
    this.msg(LogType.DEBUG, msg)
  },
  msg (logType: LogType, msg: string | Error | Object | any[]) {
    if (logType.level < config.log.level) {
      return
    }

    let dateTime = config.log.time
      ? colors.gray(`[${getDateTime()}] `)
      : ''

    if (_.isError(msg)) {
      msg = msg.message
    } else if (_.isPlainObject(msg) || _.isArray(msg)) {
      msg = JSON.stringify(msg)
    }

    if (this.cb) {
      this.cb(msg, logType, dateTime)
    } else {
      let color = colors[logType.color]
      msg = dateTime + color(`[${logType.desc}]`) + ' ' + msg

      if (logType.level >= LogLevel.WARN) {
        console.error(msg)
      } else {
        console.log(msg)
开发者ID:bbxyard,项目名称:bbxyard,代码行数:31,代码来源:log.ts


示例4: isError

export const error = (value: any): value is Error => isError(value)
开发者ID:bcherny,项目名称:tassert,代码行数:1,代码来源:tassert.ts


示例5: logError

 logError(level, message, err) {
   const errorMessage = _.isError(err)
     ? err.message
     : err
   this.log(level, `${message}. Error:${errorMessage}`)
 }
开发者ID:carlosrfernandez,项目名称:ReactiveTraderCloud,代码行数:6,代码来源:logger.ts


示例6:

 args.forEach(arg => {
   if (_.isError(arg)) {
     HoneyBadger.notify(arg)
   }
 })
开发者ID:influxdata,项目名称:influxdb,代码行数:5,代码来源:overrides.ts


示例7: getFile

    if ( !config['configPath'] ) delete config['configPath'];

    return config;

  },

  async getFile ( filePath ) {

    const content = await Utils.file.read ( filePath );

    if ( !content || !content.trim () ) return;

    const config: any = _.attempt ( JSON5.parse, content );

    if ( _.isError ( config ) ) {

      const option = await vscode.window.showErrorMessage ( '[{{displayName}}] Your configuration file contains improperly formatted JSON', { title: 'Overwrite' }, { title: 'Edit' } );

      if ( option && option.title === 'Overwrite' ) {

        await Utils.file.write ( filePath, '{}' );

        return {};

      } else {

        if ( option && option.title === 'Edit' ) {

          Utils.file.open ( filePath );
开发者ID:fabiospampinato,项目名称:template-vscode-extension,代码行数:29,代码来源:config.ts



注:本文中的lodash.isError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.isFinite函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.isEqual函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap