{"_id":"@q42philips/node-grpc-error-details","_rev":"28-93f8e6ef394e84084c50b47c1f978d0e","name":"@q42philips/node-grpc-error-details","dist-tags":{"latest":"2.1.0"},"versions":{"2.0.0":{"name":"@q42philips/node-grpc-error-details","version":"2.0.0","author":{"name":"Q42"},"license":"MIT","_id":"@q42philips/node-grpc-error-details@2.0.0","maintainers":[{"name":"dtaspinar","email":"duygu.taspinar@signify.com"},{"name":"arjenvanderende","email":"arjen@q42.nl"},{"name":"djovanni","email":"djovanni@q42.nl"},{"name":"keesvv-q42","email":"kees@q42.nl"},{"name":"sjorsdebipersad","email":"sjorsdebipersad@gmail.com"},{"name":"basvda","email":"basvda@q42.nl"},{"name":"michielkeij","email":"michiel.keij@polteq.com"},{"name":"_daanq42","email":"daan@q42.nl"},{"name":"wesleyklop","email":"wesley19097@gmail.com"},{"name":"merwinq42","email":"merwin@q42.nl"},{"name":"morgenstond","email":"arian@q42.nl"},{"name":"korjan","email":"korjanvanwieringen@gmail.com"},{"name":"hermanbanken","email":"hermanbanken@gmail.com"},{"name":"edeijl","email":"erik.deijl@gmail.com"},{"name":"timonvw","email":"timonvanwaardhuizen@gmail.com"},{"name":"klmz","email":"joostnaaijen@q42.nl"},{"name":"marnix_q42","email":"marnix@q42.nl"},{"name":"leroy-jenkins","email":"hue+jenkins@q42.nl"}],"dist":{"shasum":"a65f8e7f443475d0d33fdfecc6cee40802ec3f02","tarball":"https://registry.npmjs.org/@q42philips/node-grpc-error-details/-/node-grpc-error-details-2.0.0.tgz","fileCount":23,"integrity":"sha512-ebhU56+Sh2XRlknS24yuX74hkB5D34u6guj3Xl++dPT8k4PXP+BzzVT7UBWXcKaJz7KmmcD5dA0Cu/gW2eOjFg==","signatures":[{"sig":"MEYCIQCaLd/jK4qbYM29NTbZI6Q1yVwlH8C5QTf5e8YqsDwplgIhAIxtfKo2l7a0CZ6fyAo8D7shoQ15f3VJmq6CDzgkTECJ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":155957},"jest":{"roots":["<rootDir>/src"],"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"]},"main":"build/index.js","types":"build/index.d.ts","volta":{"node":"18.17.0"},"gitHead":"19cffa0bedba78096aa0c9da74a2b3f4263a8566","scripts":{"lint":"prettier --check .","test":"jest","build":"tsc","genProto":"protoc --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin -I src/proto --js_out=import_style=commonjs,binary:./src/generated ./src/proto/*.proto && protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts -I src/proto --ts_out=./src/generated ./src/proto/*.proto"},"_npmUser":{"name":"merwinq42","email":"merwin@q42.nl"},"_npmVersion":"9.6.7","description":"Utility for deserializing grpc-status-details-bin","directories":{},"_nodeVersion":"18.17.0","dependencies":{"@types/node":"*","@grpc/grpc-js":"^1.8.8","google-protobuf":"^3.11.4","@types/google-protobuf":"^3.15.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.6.2","ts-jest":"^29.1.1","prettier":"^3.0.0","grpc-tools":"1.12.4","typescript":"^5.1.6","@types/jest":"^29.5.3","grpc_tools_node_protoc_ts":"^5.3.3"},"_npmOperationalInternal":{"tmp":"tmp/node-grpc-error-details_2.0.0_1690534447837_0.9724229904003698","host":"s3://npm-registry-packages"}},"2.1.0":{"name":"@q42philips/node-grpc-error-details","version":"2.1.0","author":{"name":"Q42"},"license":"MIT","_id":"@q42philips/node-grpc-error-details@2.1.0","maintainers":[{"name":"dtaspinar","email":"duygu.taspinar@signify.com"},{"name":"arjenvanderende","email":"arjen@q42.nl"},{"name":"djovanni","email":"djovanni@q42.nl"},{"name":"keesvv-q42","email":"kees@q42.nl"},{"name":"sjorsdebipersad","email":"sjorsdebipersad@gmail.com"},{"name":"basvda","email":"basvda@q42.nl"},{"name":"michielkeij","email":"michiel.keij@polteq.com"},{"name":"_daanq42","email":"daan@q42.nl"},{"name":"wesleyklop","email":"wesley19097@gmail.com"},{"name":"merwinq42","email":"merwin@q42.nl"},{"name":"morgenstond","email":"arian@q42.nl"},{"name":"korjan","email":"korjanvanwieringen@gmail.com"},{"name":"hermanbanken","email":"hermanbanken@gmail.com"},{"name":"edeijl","email":"erik.deijl@gmail.com"},{"name":"timonvw","email":"timonvanwaardhuizen@gmail.com"},{"name":"klmz","email":"joostnaaijen@q42.nl"},{"name":"marnix_q42","email":"marnix@q42.nl"},{"name":"leroy-jenkins","email":"hue+jenkins@q42.nl"}],"dist":{"shasum":"c421e5451b187f4d6953daba8b4d00622289f52c","tarball":"https://registry.npmjs.org/@q42philips/node-grpc-error-details/-/node-grpc-error-details-2.1.0.tgz","fileCount":27,"integrity":"sha512-oVtqtlt7AM60ULB3y3+aX3Z4BR3cfnoCIsQ+nwkElD6ODuX/A7rTEqBJqL3yPk18Z9HGDse5pug4QWCmXwObiw==","signatures":[{"sig":"MEUCIQDPoY2HUsf8XPhbhypjixRJroooftRzfx+lfiHkyiAT3AIgJZu65N6G9EvITbvAmEo9cclN7tJ4RdOOVfeo60Tvj9A=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":258646},"jest":{"roots":["<rootDir>/src"],"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"]},"main":"build/index.js","types":"build/index.d.ts","volta":{"node":"18.17.0"},"gitHead":"fdc4aea7d066e9d3287d3b818b03237495e48c9b","scripts":{"lint":"prettier --check .","test":"jest","build":"tsc && mkdir -p build/generated && cp src/generated/* build/generated/","genProto":"protoc --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin -I src/proto --js_out=import_style=commonjs,binary:./src/generated ./src/proto/*.proto && protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts -I src/proto --ts_out=./src/generated ./src/proto/*.proto"},"_npmUser":{"name":"merwinq42","email":"merwin@q42.nl"},"_npmVersion":"9.6.7","description":"Utility for deserializing grpc-status-details-bin","directories":{},"_nodeVersion":"18.17.0","dependencies":{"@types/node":"*","@grpc/grpc-js":"^1.8.8","google-protobuf":"^3.11.4","@types/google-protobuf":"^3.15.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.6.2","ts-jest":"^29.1.1","prettier":"^3.0.0","grpc-tools":"1.12.4","typescript":"^5.1.6","@types/jest":"^29.5.3","grpc_tools_node_protoc_ts":"^5.3.3"},"_npmOperationalInternal":{"tmp":"tmp/node-grpc-error-details_2.1.0_1690536215319_0.08168640542948147","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-07-28T08:54:07.836Z","modified":"2026-07-28T09:01:22.367Z","2.0.0":"2023-07-28T08:54:08.122Z","2.1.0":"2023-07-28T09:23:35.518Z"},"author":{"name":"Q42"},"license":"MIT","description":"Utility for deserializing grpc-status-details-bin","maintainers":[{"email":"arian@q42.nl","name":"morgenstond"},{"email":"korjanvanwieringen@gmail.com","name":"korjan"},{"email":"hermanbanken@gmail.com","name":"hermanbanken"},{"email":"daan@q42.nl","name":"_daanq42"},{"email":"timonvanwaardhuizen@gmail.com","name":"timonvw"},{"email":"joostnaaijen@q42.nl","name":"klmz"},{"email":"contact@techwolf12.nl","name":"techwolf12"},{"email":"roy.touw@q42.nl","name":"roytouwq42"},{"email":"hue+npm-ci@q42.nl","name":"hue-ci"},{"email":"kexin.su823@gmail.com","name":"kexin_su"},{"email":"erik.deijl@gmail.com","name":"edeijl"},{"email":"jordylangen@gmail.com","name":"xylez"},{"email":"jorre.vanmunster@polteq.com","name":"jorrevanmunster"},{"email":"noah.loomans@q42.nl","name":"nloomans-q42"},{"email":"job.verhoeven_1@signify.com","name":"jverh"},{"email":"jolien.schuurmans@q42.nl","name":"jpschuurmans"}],"readme":"# node-grpc-error-details\n\n[![Build and test](https://github.com/Q42Philips/node-grpc-error-details/actions/workflows/build-and-test.yaml/badge.svg)](https://github.com/Q42Philips/node-grpc-error-details/actions/workflows/build-and-test.yaml)\n\nUtility function for deserializing the `grpc-status-details-bin` metadata value when using the [grpc-js](https://github.com/grpc/grpc-node) package. Error details allow sending/receiving additional data along with an error. For instance, if a request sends invalid data, a gRPC server could send back a [BadRequest](./src/proto/error_details.proto#L119) message identifying the field and why it failed validation.\n\ngRPC services that send rich error details place information in the `grpc-status-details-bin` metadata property of the [ServiceError](https://grpc.io/grpc/node/grpc.html#~ServiceError) passed to the callback of a failed gRPC method call. The value of the `grpc-status-details-bin` field is a serialized [Status](./src/proto/status.proto) message. The Status message's details field is an array of [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto#L122) messages, which consist of a type field and the serialized data for that message type.\n\nThis library, given an error, returns back the deserialized Status message and an array of deserialized detail messages.\n\n## Install\n\n```bash\n# npm\nnpm install @q42philips/node-grpc-error-details\n```\n\n## Usage\n\nBoth exported functions return the same type of object.\n\n```\n{\n  status: Status\n  details: DetailType[]\n}\n```\n\nwhere `status` is a [Google rpc Status message](./src/proto/status.proto) and `details` is the `Status`'s details array with each item deserialized and unpacked from an `Any` message to its actual message type.\n\n`deserializeGrpcStatusDetails` allows passing in the `deserializeMap` argument, where each key is a message type and each value is its corresponding deserialize function.\n\n`deserializeGoogleGrpcStatusDetails` behaves exactly the same as `deserializeGrpcStatusDetails`, but provides a default deserializeMap using [Google's rpc error details types](./src/proto/error_details.proto).\n### deserializeGoogleGrpcStatusDetails(error)\n\nExample:\n\n```ts\nimport {\n  deserializeGoogleGrpcStatusDetails,\n  BadRequest\n} from \"@q42philips/node-grpc-error-details\";\n\nconst point = { latitude: 409146138, longitude: -746188906 };\n\n// Make grpc call that fails and returns a Status object with\n// details in the `grpc-status-details-bin` Metadata property\nstub.getFeature(point, function(err, feature) {\n  if (err) {\n    const grpcErrorDetails = deserializeGoogleGrpcStatusDetails(err);\n    if (grpcErrorDetails) {\n      const { status, details } = grpcErrorDetails;\n\n      // Search for an instance of BadRequest in details and do something if found\n      for (let i = 0; i < details.length; i++) {\n        if (details[i] instanceof BadRequest) {\n          console.log(details[i].toObject());\n        }\n      }\n    }\n  } else {\n    // process feature\n  }\n});\n```\n\n### deserializeGrpcStatusDetails(error, deserializeMap)\n\nExample:\n\n```ts\nimport { deserializeGrpcStatusDetails } from \"@q42philips/node-grpc-error-details\";\nimport {\n  RetryInfo,\n  DebugInfo,\n  QuotaFailure,\n  PreconditionFailure,\n  CustomError\n} from \"./custom_error_pb\";\n\n// Define the types of errors we want to deserialize\nconst deserializeMap = {\n  \"stackpath.rpc.RetryInfo\": RetryInfo.deserializeBinary,\n  \"stackpath.rpc.DebugInfo\": DebugInfo.deserializeBinary,\n  \"stackpath.rpc.QuotaFailure\": QuotaFailure.deserializeBinary,\n  \"stackpath.rpc.PreconditionFailure\": PreconditionFailure.deserializeBinary,\n  \"stackpath.rpc.CustomError\": CustomError.deserializeBinary\n};\n\nconst point = { latitude: 409146138, longitude: -746188906 };\n\n// Make grpc call that fails and returns a Status object with\n// details in the `grpc-status-details-bin` Metadata property\nstub.getFeature(point, function(err, feature) {\n  if (err) {\n    const grpcErrorDetails = deserializeGrpcStatusDetails(err, deserializeMap);\n    if (grpcErrorDetails) {\n      const { status, details } = grpcErrorDetails;\n\n      // Search for an instance of CustomError in details and do something if found\n      for (let i = 0; i < details.length; i++) {\n        if (details[i] instanceof CustomError) {\n          console.log(details[i].toObject());\n        }\n      }\n    }\n  } else {\n    // process feature\n  }\n});\n```\n","readmeFilename":"README.md"}