Files
codeql-action/node_modules/@protobuf-ts/runtime-rpc/build/es2015/rpc-error.js
Angela P Wen a196a714b8 Bump artifact dependencies if CODEQL_ACTION_ARTIFACT_V2_UPGRADE enabled (#2482)
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
Co-authored-by: Henry Mercer <henrymercer@github.com>
2024-10-01 09:59:05 -07:00

33 lines
1.0 KiB
JavaScript

/**
* An error that occurred while calling a RPC method.
*/
export class RpcError extends Error {
constructor(message, code = 'UNKNOWN', meta) {
super(message);
this.name = 'RpcError';
// see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#example
Object.setPrototypeOf(this, new.target.prototype);
this.code = code;
this.meta = meta !== null && meta !== void 0 ? meta : {};
}
toString() {
const l = [this.name + ': ' + this.message];
if (this.code) {
l.push('');
l.push('Code: ' + this.code);
}
if (this.serviceName && this.methodName) {
l.push('Method: ' + this.serviceName + '/' + this.methodName);
}
let m = Object.entries(this.meta);
if (m.length) {
l.push('');
l.push('Meta:');
for (let [k, v] of m) {
l.push(` ${k}: ${v}`);
}
}
return l.join('\n');
}
}