@join-com/grpc
Advanced tools
Comparing version 3.3.6 to 3.3.7
@@ -31,4 +31,7 @@ import * as grpc from '@grpc/grpc-js'; | ||
private getGrpcStatusCode; | ||
private failIfDisabled; | ||
private getDisableServices; | ||
private getServiceName; | ||
} | ||
export {}; | ||
//# sourceMappingURL=Service.d.ts.map |
@@ -93,2 +93,3 @@ "use strict"; | ||
}; | ||
this.failIfDisabled(methodDefinition.path, call.metadata); | ||
// Promise.resolve guarantees that the handler is always executed asynchronously. | ||
@@ -170,2 +171,28 @@ // Ex. handler can be defined as a synchronous function returning promise and throwing error inside. | ||
} | ||
failIfDisabled(path, metadata) { | ||
const serviceName = this.getServiceName(path); | ||
const disableServices = this.getDisableServices(metadata); | ||
if (serviceName && disableServices?.includes(serviceName)) { | ||
throw new Error(`Remote call "${path}" cancelled. Found ${disableServices.toString()} disable-services in metadata`); | ||
} | ||
} | ||
getDisableServices(metadata) { | ||
const metadataValue = metadata.get('chaos_mode.disable_services'); | ||
if (metadataValue.length === 1) { | ||
const val = metadataValue[0]; | ||
if (typeof val === 'string') { | ||
return val.split(','); | ||
} | ||
} | ||
return undefined; | ||
} | ||
getServiceName(path) { | ||
const regex = /^\/([^.]+)/; | ||
const matches = path.match(regex); | ||
if (matches && matches[1]) { | ||
const extractedString = matches[1]; | ||
return extractedString; | ||
} | ||
return undefined; | ||
} | ||
} | ||
@@ -172,0 +199,0 @@ exports.Service = Service; |
{ | ||
"name": "@join-com/grpc", | ||
"version": "3.3.6", | ||
"version": "3.3.7", | ||
"description": "gRPC library", | ||
@@ -5,0 +5,0 @@ "author": "JOIN Solutions", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
82088
879