How to use the @loopback/rest.HttpErrors.NotFound function in @loopback/rest

To help you get started, we’ve selected a few @loopback/rest 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 strongloop / loopback-next / packages / example-codehub / src / controllers / user-controller.ts View on Github external
public async getAuthenticatedUser(
    @inject('userId') userId: number,
  ): Promise {
    if (userId !== 42) {
      // using "return Promise.reject(err)" would be probably faster
      // (a possible micro-optimization)
      throw new HttpErrors.NotFound('Current user not found (?!).');
    }

    return new UserResponse({
      id: userId,
      name: 'Admin',
      email: 'admin@example.com',
    });
  }
github strongloop / loopback4-example-shopping / packages / shopping / src / controllers / shopping-cart.controller.ts View on Github external
async get(
    @param.path.string('userId') userId: string,
  ): Promise {
    debug('Get shopping cart %s', userId);
    const cart = await this.shoppingCartRepository.get(userId);
    debug('Shopping cart %s: %j', userId, cart);
    if (cart == null) {
      throw new HttpErrors.NotFound(
        `Shopping cart not found for user: ${userId}`,
      );
    } else {
      return cart;
    }
  }