grpc-rich-error-model
Advanced tools
Comparing version
@@ -42,3 +42,3 @@ import { Metadata, status, StatusObject } from '@grpc/grpc-js'; | ||
} | ||
declare type StatusToErrorDetailType = { | ||
interface StatusToErrorDetailType { | ||
[status.ABORTED]: ErrorInfo; | ||
@@ -58,3 +58,3 @@ [status.ALREADY_EXISTS]: ResourceInfo; | ||
[status.UNKNOWN]: DebugInfo; | ||
}; | ||
} | ||
export declare type ErrorDetailsForStatus<Status extends status> = Status extends keyof StatusToErrorDetailType ? StatusToErrorDetailType[Status] : never; | ||
@@ -68,5 +68,4 @@ export declare type ErrorDetails = BadRequest | DebugInfo | ErrorInfo | PreconditionFailure | QuotaFailure | ResourceInfo; | ||
export declare const makeMetadataWithEncodedErrorDetails: (code: StatusObject['code'], message: string, errorDetails: ErrorDetails) => Metadata; | ||
export declare const getErrorMetadataForCode: <Status extends status>(code: Status, message: string, errorDetails: ErrorDetailsForStatus<Status>) => Metadata; | ||
export declare class GrpcError<Status extends status> extends grpc.Error { | ||
readonly code: Status; | ||
export declare class GrpcError<Status extends StatusObject['code']> extends grpc.Error { | ||
readonly code: StatusObject['code']; | ||
readonly details: string; | ||
@@ -73,0 +72,0 @@ readonly metadata: Metadata; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GrpcError = exports.getErrorMetadataForCode = exports.makeMetadataWithEncodedErrorDetails = exports.ErrorDetailProtobufType = exports.StatusMessageType = void 0; | ||
exports.GrpcError = exports.makeMetadataWithEncodedErrorDetails = exports.ErrorDetailProtobufType = exports.StatusMessageType = void 0; | ||
const grpc_js_1 = require("@grpc/grpc-js"); | ||
@@ -107,6 +107,5 @@ const run_1 = require("@ridedott/run"); | ||
}; | ||
exports.getErrorMetadataForCode = getErrorMetadataForCode; | ||
class GrpcError extends run_1.grpc.Error { | ||
constructor(code, message, errorDetails) { | ||
const metadata = (0, exports.getErrorMetadataForCode)(code, message, errorDetails); | ||
const metadata = getErrorMetadataForCode(code, message, errorDetails); | ||
super(code, message, { metadata }); | ||
@@ -113,0 +112,0 @@ Object.defineProperty(this, "code", { |
@@ -42,3 +42,3 @@ import { Metadata, status, StatusObject } from '@grpc/grpc-js'; | ||
} | ||
declare type StatusToErrorDetailType = { | ||
interface StatusToErrorDetailType { | ||
[status.ABORTED]: ErrorInfo; | ||
@@ -58,3 +58,3 @@ [status.ALREADY_EXISTS]: ResourceInfo; | ||
[status.UNKNOWN]: DebugInfo; | ||
}; | ||
} | ||
export declare type ErrorDetailsForStatus<Status extends status> = Status extends keyof StatusToErrorDetailType ? StatusToErrorDetailType[Status] : never; | ||
@@ -68,5 +68,4 @@ export declare type ErrorDetails = BadRequest | DebugInfo | ErrorInfo | PreconditionFailure | QuotaFailure | ResourceInfo; | ||
export declare const makeMetadataWithEncodedErrorDetails: (code: StatusObject['code'], message: string, errorDetails: ErrorDetails) => Metadata; | ||
export declare const getErrorMetadataForCode: <Status extends status>(code: Status, message: string, errorDetails: ErrorDetailsForStatus<Status>) => Metadata; | ||
export declare class GrpcError<Status extends status> extends grpc.Error { | ||
readonly code: Status; | ||
export declare class GrpcError<Status extends StatusObject['code']> extends grpc.Error { | ||
readonly code: StatusObject['code']; | ||
readonly details: string; | ||
@@ -73,0 +72,0 @@ readonly metadata: Metadata; |
@@ -59,3 +59,3 @@ import { Metadata, status } from '@grpc/grpc-js'; | ||
}; | ||
export const getErrorMetadataForCode = (code, message, errorDetails) => { | ||
const getErrorMetadataForCode = (code, message, errorDetails) => { | ||
const errorDetailType = mapGrpcErrorToErrorDetailProtobufType[code]; | ||
@@ -62,0 +62,0 @@ switch (errorDetailType) { |
@@ -6,3 +6,3 @@ { | ||
"type": "module", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": { | ||
@@ -20,3 +20,3 @@ "name": "Oleg Gaydarenko", | ||
"@grpc/grpc-js": "^1.5.9", | ||
"@ridedott/run": "^2.4.41", | ||
"@ridedott/run": "^3.2.11", | ||
"google-proto-files": "^2.5.0", | ||
@@ -31,4 +31,4 @@ "proto3-json-serializer": "^0.1.8" | ||
"@commitlint/config-conventional": "^16.2.1", | ||
"@grpc/proto-loader": "^0.6.9", | ||
"@ridedott/eslint-config": "^2.14.5", | ||
"@grpc/proto-loader": "^0.6.13", | ||
"@ridedott/eslint-config": "^2.19.5", | ||
"@types/jest": "^27.4.1", | ||
@@ -39,3 +39,3 @@ "@types/node": "^17.0.21", | ||
"cspell": "^5.19.2", | ||
"eslint": "^7.32.0", | ||
"eslint": "^7.18.0", | ||
"http-status-codes": "^2.2.0", | ||
@@ -46,2 +46,3 @@ "jest": "^27.5.1", | ||
"prettier": "^2.6.0", | ||
"protobufjs": "^6.11.3", | ||
"ts-node": "^9.1.1", | ||
@@ -48,0 +49,0 @@ "typescript": "^4.6.2" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
132829
-0.34%21
5%2827
-0.11%Updated