How to use the @grpc/grpc-js.status function in @grpc/grpc-js

To help you get started, we’ve selected a few @grpc/grpc-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleCloudPlatform / esp-v2 / tests / endpoints / bookstore_grpc / grpc_server.js View on Github external
return function(call, callback) {
    var testValues = call.metadata.get('x-grpc-test');
    var firstTestValue = undefined;
    if (testValues != undefined && testValues.length > 0) {
      firstTestValue = testValues[0];
    }
    // Add more gRPC statuses as needed.
    switch (firstTestValue) {
      case 'ABORTED':
        callback({
          code: grpc.status.ABORTED,  // 10
          message: 'ABORTED',
        });
        break;
      case 'INTERNAL':
        callback({
          code: grpc.status.INTERNAL,  // 13
          message: 'INTERNAL',
        });
        break;
      case 'DATA_LOSS':
        callback({
          code: grpc.status.DATA_LOSS,  // 15
          message: 'DATA_LOSS',
        });
        break;
      default:
github googleforgames / agones / sdks / nodejs / src / agonesSDK.js View on Github external
stream.on('error', (error) => {
			if (error.code === grpc.status.CANCELLED) {
				// Capture error when call is cancelled
				return;
			}
			throw error;
		});
		this.streams.push(stream);
github hyperledger / burrow / js / src / lib / contracts / function.ts View on Github external
let post = function (error: Error, result: TxExecution) {
        if (error) return reject(error)

        // Handle execution reversions
        if (result.hasException()) {
          // Decode error message if there is one otherwise default
          if (result.getResult().getReturn().length === 0) {
            return reject(callErrorFromStatus({
              code: grpc.status.ABORTED,
              metadata: new Metadata(),
              details: 'Execution Reverted',
            }))
          } else {
            // Strip first 4 bytes(function signature) the decode as a string
            return reject(callErrorFromStatus({
              code: grpc.status.ABORTED,
              metadata: new Metadata(),
              details: coder.rawDecode(['string'], Buffer.from(result.getResult().getReturn_asU8().slice(4)))[0],
            }))
          }
        }

        // Meta Data (address, caller, height, etc)
        let returnObj: TransactionResult = {
          contractAddress: Buffer.from(result.getReceipt().getContractaddress_asU8()).toString('hex').toUpperCase(),
          height: result.getHeader().getHeight(),
          index: result.getHeader().getIndex(),
          hash: Buffer.from(result.getHeader().getTxhash_asU8()).toString('hex').toUpperCase(),
          type: result.getHeader().getTxtype(),
          result: result.getResult().toObject(),
          tx: result.getEnvelope().toObject(),
          caller: convert.recApply(convert.bytesTB, result.getEnvelope().getSignatoriesList().map(sig => sig.getAddress_asU8())),
github hyperledger / burrow / js / src / contracts / call.ts View on Github external
}
      if (txe.hasException()) {
        // Decode error message if there is one otherwise default
        if (result.getReturn().length === 0) {
          return reject(
            callErrorFromStatus({
              code: grpc.status.ABORTED,
              metadata: new Metadata(),
              details: 'Execution Reverted',
            }),
          );
        } else {
          // Strip first 4 bytes(function signature) the decode as a string
          return reject(
            callErrorFromStatus({
              code: grpc.status.ABORTED,
              metadata: new Metadata(),
              details: coder.decode(['string'], Buffer.from(result.getReturn_asU8().slice(4)))[0],
            }),
          );
        }
      }

      // Meta Data (address, caller, height, etc)
      const envelope = txe.getEnvelope();
      const receipt = txe.getReceipt();
      if (!header || !envelope || !receipt) {
        return reject(new Error(``));
      }
      let caller: string | string[] = envelope.getSignatoriesList().map((sig) => sig.getAddress_asB64().toUpperCase());
      if (caller.length === 1) {
        caller = caller[0];
github cjihrig / grpc-server-js / test / deadline.js View on Github external
client.makeUnaryRequest(path, serialize, deserialize, {}, metadata, {}, (error, response) => {
      Assert.strictEqual(error.code, Grpc.status.OUT_OF_RANGE);
      Assert.strictEqual(error.details, 'Invalid deadline');
      barrier.pass();
    });
github cjihrig / grpc-server-js / test / deadline.js View on Github external
client.makeUnaryRequest(path, serialize, deserialize, {}, metadata, {}, (error, response) => {
      Assert.strictEqual(error.code, Grpc.status.DEADLINE_EXCEEDED);
      Assert.strictEqual(error.details, 'Deadline exceeded');
      barrier.pass();
    });
github cjihrig / grpc-server-js / test / server.js View on Github external
call.on('error', (err) => {
          Assert(err);
          Assert.strictEqual(err.code, Grpc.status.UNIMPLEMENTED);
          barrier.pass();
        });
github andrewosh / hyperdrive-daemon / lib / errors.js View on Github external
function serverError (err) {
  return {
    code: grpc.status.UNKNOWN,
    message: err.toString()
  }
}
github hyperledger / burrow / js / src / lib / events.ts View on Github external
    stream.on('error', (err: Error) => err.code === grpc.status.CANCELLED || callback(err, null));
    return stream;
github grpc / grpc-web / net / grpc / gateway / examples / echo / node-server / server.js View on Github external
function doEchoAbort(call, callback) {
  callback({
    code: grpc.status.ABORTED,
    message: 'Aborted from server side.'
  });
}