Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-manager-bridge/src/rpc.ts
2498 views
1
/**
2
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import * as grpc from "@grpc/grpc-js";
8
import { ServiceError as grpcServiceError } from "@grpc/grpc-js";
9
10
export class GRPCError extends Error implements Partial<grpcServiceError> {
11
public name = "ServiceError";
12
13
details: string;
14
15
constructor(public readonly status: grpc.status, err: any) {
16
super(GRPCError.errToMessage(err));
17
18
this.details = this.message;
19
}
20
21
static errToMessage(err: any): string | undefined {
22
if (typeof err === "string") {
23
return err;
24
} else if (typeof err === "object") {
25
return err.message;
26
}
27
}
28
29
static isGRPCError(obj: any): obj is GRPCError {
30
return obj !== undefined && typeof obj === "object" && "status" in obj;
31
}
32
}
33
34