Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

Map gRPC error

import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { Metadata, status } from '@grpc/grpc-js';
import { RpcException } from '@nestjs/microservices';

export interface IUserDecorator {
  clientId: string;
}

export const User = createParamDecorator(
  (data, context: ExecutionContext): IUserDecorator => {
    const metadata = context.switchToRpc().getContext() as Metadata;
    const { clientid } = metadata.getMap();

    if (!clientid) {
      throw new RpcException({
        code: status.UNAUTHENTICATED,
        message: 'clientId is required',
      });
    }

    return {
      clientId: clientid.toString(),
    };
  },
);
Comment

PREVIOUS NEXT
Code Example
Typescript :: take two inputs from user and add them using callback function 
Typescript :: Which Protect Presentation option protects a presentation from accidental changes: 
Typescript :: famous scientists who contributed to electricity 
Typescript :: Summation with limits in MATLAB 
Typescript :: find unique elements in pandas and their connection with other column 
Typescript :: nestjs: Starter command line 
Typescript :: CREATE FUNCTION which accepts LIST as argument 
Typescript :: nativescript date input validation 
Typescript :: Which of the following statements will compile correctly? 
Typescript :: how to get all posible subb lists in python 
Typescript :: typescript programmatically union 
Typescript :: top 100 employers in the united states 
Typescript :: typescript timeout browser 
Typescript :: jwt.verify into promise mongoose with typescript 
Typescript :: how to install tsu 
Typescript :: ex term 15 
Typescript :: how to check weather a file exists using os module 
Typescript :: convert angle to 0-360 godot 
Typescript :: java a program that converts letters to their corrosponding telephone digits 
Typescript :: why my res.data returns array of objects ? (AngularJs) 
Typescript :: how to get the elements of a pair scheme 
Typescript :: ionic ios REST API CORS issue 
Typescript :: aws elastic web python stops ajax requests if new request is made 
Typescript :: struts 2 rest api example 
Typescript :: ignoring header x-firebase-locale because its value was null. flutter 
Typescript :: reach router path typescript error 
Typescript :: how to compile in typescript 
Typescript :: creating different objects in node.js 
Typescript :: install dependencies angular 
Typescript :: how to make the inputs become a sum python 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =