How to use the @grpc/grpc-js.status.INTERNAL 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 cjihrig / grpc-server-js / lib / server-call.js View on Github external
function onStreamError (err) {
  // `this` is bound to the Call instance, not the stream itself.
  this.sendError(err, Status.INTERNAL);
}
github googleapis / nodejs-pubsub / test / pull-retry.ts View on Github external
it('should return true for retryable errors', () => {
      [
        status.OK,
        status.CANCELLED,
        status.UNKNOWN,
        status.DEADLINE_EXCEEDED,
        status.RESOURCE_EXHAUSTED,
        status.ABORTED,
        status.INTERNAL,
        status.UNAVAILABLE,
        status.DATA_LOSS,
      ].forEach((code: status) => {
        const shouldRetry = retrier.retry({code} as StatusObject);
        assert.strictEqual(shouldRetry, true);
      });
    });
github cjihrig / grpc-server-js / lib / handler.js View on Github external
async _write (chunk, encoding, callback) {
    try {
      const response = await this[kCall].serializeMessage(chunk);

      if (this[kCall].write(response) === false) {
        this[kCall].once('drain', callback);
        return;
      }
    } catch (err) {
      err.code = Status.INTERNAL;
      this.emit('error', err);
    }

    callback();
  }
github cjihrig / grpc-server-js / lib / server.js View on Github external
const call = new ServerCall(stream);

    try {
      const path = headers[HTTP2_HEADER_PATH];
      const handler = grpcServer[kHandlers].get(path);

      if (handler === undefined) {
        return call.sendError(unimplementedStatusResponse);
      }

      const metadata = call.receiveMetadata(headers);

      call.handler = handler;
      handlerTypes[handler.type](call, handler, metadata);
    } catch (err) {
      call.sendError(err, status.INTERNAL);
    }
  });
github cjihrig / grpc-server-js / lib / server-call.js View on Github external
}

      this.sendError(err);
      return;
    }

    try {
      const response = await this.serializeMessage(value);

      if (metadata) {
        this.status.metadata = metadata;
      }

      this.end(response);
    } catch (err) {
      this.sendError(err, Status.INTERNAL);
    }
  }
github googleapis / nodejs-pubsub / src / pull-retry.ts View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */
import {StatusObject, status} from '@grpc/grpc-js';

/*!
 * retryable status codes
 */
export const RETRY_CODES: status[] = [
  status.OK,
  status.CANCELLED,
  status.UNKNOWN,
  status.DEADLINE_EXCEEDED,
  status.RESOURCE_EXHAUSTED,
  status.ABORTED,
  status.INTERNAL,
  status.UNAVAILABLE,
  status.DATA_LOSS,
];

/**
 * Used to track pull requests and determine if additional requests should be
 * made, etc.
 *
 * @class
 * @private
 */
export class PullRetry {
  private failures = 0;
  /**
   * Generates a timeout that can be used for applying a backoff based on the
   * current number of failed requests.