@join-com/grpc-ts
Advanced tools
Comparing version 1.0.0-8 to 1.1.0-pre
@@ -30,2 +30,4 @@ import * as grpc from 'grpc'; | ||
}; | ||
protected assignError(metadata: grpc.Metadata, errorJSON: any, code?: grpc.status): ClientError; | ||
protected handleMetaError(metadata: grpc.Metadata, code?: grpc.status): ClientError | undefined; | ||
protected convertError(err: grpc.ServiceError): ClientError; | ||
@@ -32,0 +34,0 @@ private metadata; |
@@ -48,12 +48,24 @@ "use strict"; | ||
} | ||
assignError(metadata, errorJSON, code) { | ||
const error = new ClientError_1.ClientError(); | ||
Object.assign(error, Object.assign({}, errorJSON, { grpcCode: code, metadata: metadata })); | ||
return error; | ||
} | ||
handleMetaError(metadata, code) { | ||
const metadataError = metadata.get('error'); // deprecated, remove in next version | ||
const metadataBinaryError = metadata.get('error-bin'); | ||
if (!metadataError.length && !metadataBinaryError.length) { | ||
return; | ||
} | ||
const errorJSON = JSON.parse(metadataBinaryError.length | ||
? metadataBinaryError[0].toString() | ||
: metadataError[0]); | ||
return this.assignError(metadata, errorJSON, code); | ||
} | ||
convertError(err) { | ||
const { metadata } = err; | ||
if (metadata) { | ||
const metadataError = metadata.get('error'); | ||
if (metadataError && metadataError.length > 0) { | ||
const errorJSON = JSON.parse(metadataError[0]); | ||
const error = new ClientError_1.ClientError(); | ||
Object.assign(error, Object.assign({}, errorJSON, { grpcCode: err.code, metadata: err.metadata })); | ||
const error = this.handleMetaError(metadata, err.code); | ||
if (error) | ||
return error; | ||
} | ||
} | ||
@@ -60,0 +72,0 @@ return Object.assign(err, { grpcCode: err.code }); |
@@ -23,3 +23,3 @@ "use strict"; | ||
const metadata = new grpc.Metadata(); | ||
metadata.set('error', JSON.stringify(e, replacer)); | ||
metadata.set('error-bin', Buffer.from(JSON.stringify(e, replacer))); | ||
callback({ | ||
@@ -26,0 +26,0 @@ code: grpc.status.UNKNOWN, |
{ | ||
"name": "@join-com/grpc-ts", | ||
"version": "1.0.0-8", | ||
"version": "1.1.0-pre", | ||
"description": "grpc typescript wrapper", | ||
@@ -41,11 +41,11 @@ "main": "./lib/index.js", | ||
"@join-com/node-trace": "^0.1.5", | ||
"@types/jest": "^23.3.9", | ||
"@types/node": "^10.12.3", | ||
"@types/jest": "^23.3.10", | ||
"@types/node": "^10.12.10", | ||
"jest": "^23.6.0", | ||
"jest-cli": "^23.6.0", | ||
"jest-watch-typeahead": "^0.2.0", | ||
"prettier": "^1.15.1", | ||
"prettier": "^1.15.2", | ||
"protobufjs": "^6.8.8", | ||
"ts-jest": "^23.10.4", | ||
"typescript": "^3.1.6" | ||
"ts-jest": "^23.10.5", | ||
"typescript": "^3.2.1" | ||
}, | ||
@@ -52,0 +52,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39333
606