Skip to content

Commit

Permalink
Internal code sync (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampajano authored Sep 26, 2022
1 parent 17e6a81 commit d1d99eb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion javascript/net/grpc/web/clientoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {StreamInterceptor, UnaryInterceptor} = goog.require('grpc.web.Interceptor


/**
* Options that are availavle during the client construction.
* Options that are available during the client construction.
* @record
*/
class ClientOptions {
Expand Down
52 changes: 51 additions & 1 deletion javascript/net/grpc/web/statuscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ goog.module('grpc.web.StatusCode');
* @enum {number}
*/
const StatusCode = {
// LINT.IfChange(status_codes)

// Not an error; returned on success.
'OK': 0,

Expand Down Expand Up @@ -136,8 +138,9 @@ const StatusCode = {

// Unrecoverable data loss or corruption.
'DATA_LOSS': 15,
};

// LINT.ThenChange(:status_code_name)
};

/**
* Convert HTTP Status code to gRPC Status code
Expand Down Expand Up @@ -218,5 +221,52 @@ StatusCode.getHttpStatus = function(statusCode) {
}
};

/**
* Returns the human readable name for a {@link StatusCode}. Useful for logging.
* @param {!StatusCode} statusCode GRPC Status Code
* @return {string} the human readable name for the status code
*/
StatusCode.statusCodeName = function(statusCode) {
switch (statusCode) {
// LINT.IfChange(status_code_name)
case StatusCode.OK:
return 'OK';
case StatusCode.CANCELLED:
return 'CANCELLED';
case StatusCode.UNKNOWN:
return 'UNKNOWN';
case StatusCode.INVALID_ARGUMENT:
return 'INVALID_ARGUMENT';
case StatusCode.DEADLINE_EXCEEDED:
return 'DEADLINE_EXCEEDED';
case StatusCode.NOT_FOUND:
return 'NOT_FOUND';
case StatusCode.ALREADY_EXISTS:
return 'ALREADY_EXISTS';
case StatusCode.PERMISSION_DENIED:
return 'PERMISSION_DENIED';
case StatusCode.UNAUTHENTICATED:
return 'UNAUTHENTICATED';
case StatusCode.RESOURCE_EXHAUSTED:
return 'RESOURCE_EXHAUSTED';
case StatusCode.FAILED_PRECONDITION:
return 'FAILED_PRECONDITION';
case StatusCode.ABORTED:
return 'ABORTED';
case StatusCode.OUT_OF_RANGE:
return 'OUT_OF_RANGE';
case StatusCode.UNIMPLEMENTED:
return 'UNIMPLEMENTED';
case StatusCode.INTERNAL:
return 'INTERNAL';
case StatusCode.UNAVAILABLE:
return 'UNAVAILABLE';
case StatusCode.DATA_LOSS:
return 'DATA_LOSS';
default:
return '';
// LINT.ThenChange(:status_codes)
}
};

exports = StatusCode;

0 comments on commit d1d99eb

Please sign in to comment.