當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。