How to use the @nestjs/core.HttpException function in @nestjs/core

To help you get started, we’ve selected a few @nestjs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github m24927605 / Nestjs30Days / day07 / Day07_Pipes / project / src / modules / Products / Services / products.service.ts View on Github external
getProduct(id: number) {
        const product = this.products.find((product) => {
            return product._id === id;
        });
        if (!product) {
            //nestjs對於http exception有API可以調用,建議使用。
            throw new HttpException("product not found", 404);
        }
        return Promise.resolve(product);
    }
    //在nestjs也是可以歡樂使用Rx.js
github cdiaz / nestjs-demo / src / modules / auth / login.service.ts View on Github external
"SELECT * FROM user WHERE email = ?", [email], (err, user) => {
              
              if(err) {
                  return reject(new HttpException(err, 503))
              }

              else {
                  if(user.length === 0) { 
                    return reject(new HttpException("User does not exist", 401))
                  } 
                  else { 
                      if (password != user[0].password) {
                          return reject(new HttpException("Incorrect password", 401))
                       }
                      else { 
                        return resolve(this.authHelper.genToken(user[0]));
                      }
                  }
              }
        });
github tsmean / tsmean / backend / src / common / pipes / parse-id.pipe.ts View on Github external
async transform(value: string, metadata: ArgumentMetadata) {
    const val = parseInt(value, 10);
    if (isNaN(val)) {
      throw new HttpException('Validation failed', HttpStatus.BAD_REQUEST);
    } else if (val <= 0) {
      throw new HttpException('Validation failed', HttpStatus.BAD_REQUEST);
    }
    return val;
  }
}
github tsmean / tsmean / backend / src / common / interceptors / exception.interceptor.ts View on Github external
    return stream$.catch(err => Observable.throw(new HttpException('Exception interceptor message', HttpStatus.BAD_GATEWAY)));
  }
github m24927605 / Nestjs30Days / day07 / Day07_Pipes / project / src / modules / Users / Services / users.service.ts View on Github external
getUser(id: number) {
        const user = this.users.find((user) => {
            return user._id === id;
        });
        if (!user) {
            //nestjs對於http exception有API可以調用,建議使用。
            throw new HttpException("user not found", 404);
        }
        return Promise.resolve(user);
    }
    //在nestjs也是可以歡樂使用Rx.js
github m24927605 / Nestjs30Days / day07 / Day07_Pipes / project / src / modules / Shared / Pipes / parse-int.pipe.ts View on Github external
async transform(value: string, metadata: ArgumentMetadata) {
        const val = parseInt(value, 10);
        if (isNaN(val)) {
            throw new HttpException('檢驗錯誤', HttpStatus.BAD_REQUEST);
        }
        return val;
    }
}
github cdiaz / nestjs-demo / src / modules / auth / login.service.ts View on Github external
public login(email, password) {

    if(!email){
      return(new HttpException("Email is required", 422))
    }
    if(!password){
      return(new HttpException("Password is required", 422))
    }

    return new Promise((resolve, reject) => {
        db.all(
            "SELECT * FROM user WHERE email = ?", [email], (err, user) => {
              
              if(err) {
                  return reject(new HttpException(err, 503))
              }

              else {
                  if(user.length === 0) { 
                    return reject(new HttpException("User does not exist", 401))
                  } 
                  else { 
                      if (password != user[0].password) {
github cdiaz / nestjs-demo / src / modules / users / users.service.ts View on Github external
"VALUES (?, ?, ?, ?, 'user')", [uuid.v1().replace(/-/g, ""), username, email, password], (err) => {
                    return !err ? 
                        resolve({'message':'User has been registered'}) :
                        reject(new HttpException(err, 500));
            });
        });