Path: blob/main/components/ws-manager-bridge/src/rpc.ts
2498 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import * as grpc from "@grpc/grpc-js";7import { ServiceError as grpcServiceError } from "@grpc/grpc-js";89export class GRPCError extends Error implements Partial<grpcServiceError> {10public name = "ServiceError";1112details: string;1314constructor(public readonly status: grpc.status, err: any) {15super(GRPCError.errToMessage(err));1617this.details = this.message;18}1920static errToMessage(err: any): string | undefined {21if (typeof err === "string") {22return err;23} else if (typeof err === "object") {24return err.message;25}26}2728static isGRPCError(obj: any): obj is GRPCError {29return obj !== undefined && typeof obj === "object" && "status" in obj;30}31}323334