當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lodash.isError函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。