Answers for "custom decorator in loopback4"

1

custom decorator in loopback4

import {inject, intercept, Interceptor} from '@loopback/context';
import {get, HttpErrors, RestBindings} from '@loopback/rest';

const myInterceptor: Interceptor = async (invocationCtx, next) => {
  // your code 
  // goes here

  // if success
  next()

  // if error
  throw new HttpErrors.NotFound();
};

export class PingController {
  constructor() {}

  @intercept(myInterceptor)
  @post('/test')
  async test(@requestBody() body: any) {
    // some code
  }
}
Posted by: Guest on October-22-2021
1

custom decorator in loopback4

import {inject, intercept, Interceptor} from '@loopback/context';
import {get, HttpErrors, RestBindings} from '@loopback/rest';

const myInterceptor: Interceptor = async (invocationCtx, next) => {
  // your code 
  // goes here

  // if success
  next()

  // if error
  throw new HttpErrors.NotFound();
};

export class PingController {
  constructor() {}

  @intercept(myInterceptor)
  @post('/test')
  async test(@requestBody() body: any) {
    // some code
  }
}
Posted by: Guest on October-22-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language