当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Promise.reject方法代码示例

本文整理汇总了TypeScript中es6-promise.Promise.reject方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise.reject方法的具体用法?TypeScript Promise.reject怎么用?TypeScript Promise.reject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在es6-promise.Promise的用法示例。


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

示例1: registerAccountCommand

export default function registerAccountCommand(registration: AccountRegistration): Thenable<Account> {
    const { emailAddress, displayName, password } = registration;

    // TODO: data-driven validation. would be awesome to reuse same validation that the client uses

    if (password.length < 8) {
        return Promise.reject(new Error(Errors.REGISTRATION_PASSWORD_TOO_SHORT));
    }
    if (!emailRegex.test(emailAddress)) {
        return Promise.reject(new Error(Errors.REGISTRATION_INVALID_EMAIL));
    }
    if (emailAddress.length > 64) {
        return Promise.reject(new Error(Errors.REGISTRATION_EMAIL_TOO_LONG));
    }

    return hashPassword(password).then(passwordHash => {
        return new Promise((resolve: Function, reject: Function) => {
            withDb(db => {
                const userId = UUID.generate();
                const created = new Date();
                var params = [ userId, emailAddress, displayName, passwordHash, created ];
                db.query(`
                    INSERT INTO public.accounts
                        (user_id, email_address, display_name, password_hash, created)
                    VALUES ($1, $2, $3, $4, $5);
                    `,
                    params,
                    (err: any) => {
                        if (err) {
                            // Distinguish between duplicate email address and all other errors
                            if (err.code === "23505" && err.constraint === "accounts_email_address_key") {
                                log.warn("Failed to insert into Accounts table because email address already exists", JSON.stringify(params));
                                reject(new Error(Errors.REGISTRATION_ADDRESS_ALREADY_REGISTERED));
                            }
                            else {
                                log.error("Failed to insert into Accounts table", JSON.stringify(params), JSON.stringify(err, null, '  '));
                                reject(err);
                            }
                            return;
                        }

                        resolve({
                            userId,
                            emailAddress,
                            displayName,
                            passwordHash,
                            created
                        });
                    }
                );
            });
        });
    });
}
开发者ID:PhilipDavis,项目名称:react-redux,代码行数:54,代码来源:RegisterAccountCommand.ts

示例2: dispatch

  (result) => {
      dispatch(onResultsAction({success: false, data: result.data}, _.get(result, "data.message", ""), _.get(result, "data", {}), "help", false, false, ACCOUNT_LINK_RESPONSE));
      
 
      
      return Promise.reject(new Error("User does not exist"));
  }
开发者ID:Emunoz88,项目名称:node-hapi-react-redux-sass-typescript-mongo-webpack-hmr-gulp,代码行数:7,代码来源:accounts.ts

示例3: jsLoader

export default function jsLoader(path: string): Promise<any>{
    try {
        return Promise.resolve(require(path));
    }catch (e){
        return Promise.reject(e);
    }
}
开发者ID:uhyo,项目名称:my-load-data,代码行数:7,代码来源:js.ts

示例4: dispatch

 .catch((err) => {
     dispatch({
         type: GET_GROUPS,
         error: new Error('Could not load admin-groups')
     })
     return Promise.reject(new Error('Could not load admin-groups'));
 })
开发者ID:Emunoz88,项目名称:node-hapi-react-redux-sass-typescript-mongo-webpack-hmr-gulp,代码行数:7,代码来源:actions.ts

示例5: startServer

export function startServer(args: CommandLineArgs, logger: Logger): Promise<Server<SocketIO.Server>> {
  const { maxPlayers, debug, port, seed } = args;
  if (isNaN(maxPlayers) || isNaN(port) || isNaN(seed)) {
    let errMsg = 'Invalid arguments (`--with-defaults` flag is suggested):\n';
    if (isNaN(maxPlayers)) {
      errMsg += '\t- maxPlayers should be a number greater than 1\n';
    }
    if (isNaN(port)) {
      errMsg += '\t- port should be a number between 0 and 65535\n';
    }
    if (isNaN(seed)) {
      errMsg += '\t- seed should be a number\n';
    }

    return Promise.reject(new Error(errMsg));
  } else {
    const server = new Server<SocketIO.Server>(SocketIO, maxPlayers, seed, debug, logger);

    // localhost <-> no remote connections
    let hostname: string;

    if (args.allowRemoteConnections) {
      hostname = Server.REMOTE_CONNECTION_ADDRESS;
    } else {
      hostname = Server.LOCALHOST_ADDRESS;
    }

    return server.start(port, hostname);
  }
}
开发者ID:zthomae,项目名称:xanadu,代码行数:30,代码来源:main.ts

示例6: read

 public read():Promise<any> {
     try {
         let file = require(this.filePath);
         return Promise.resolve(file);
     } catch (e) {
         return Promise.reject(e);
     }
 }
开发者ID:petermanser,项目名称:proc-that,代码行数:8,代码来源:JsonExtractor.ts


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