📜  loopback4 中的自定义装饰器 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:25.488000             🧑  作者: Mango

代码示例1
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
  }
}