grpc-web-error-details
Advanced tools
Comparing version 1.0.1 to 1.1.0
import { Status } from "../lib/status_pb"; | ||
import * as ErrorDetailsPb from "../lib/error_details_pb"; | ||
export declare type ErrorDetails = ErrorDetailsPb.RetryInfo | ErrorDetailsPb.DebugInfo | ErrorDetailsPb.QuotaFailure | ErrorDetailsPb.ErrorInfo | ErrorDetailsPb.PreconditionFailure | ErrorDetailsPb.BadRequest | ErrorDetailsPb.RequestInfo | ErrorDetailsPb.ResourceInfo | ErrorDetailsPb.Help | ErrorDetailsPb.LocalizedMessage; | ||
export declare function statusFromError(err: object | { | ||
export declare function statusFromError(err: any | { | ||
metadata: { | ||
"grpc-status-details-bin"?: string; | ||
}; | ||
} | { | ||
code?: number; | ||
message?: string; | ||
}): [Status, ErrorDetails[]] | [null, null]; | ||
//# sourceMappingURL=grpc-web-error-details.d.ts.map |
@@ -48,8 +48,19 @@ "use strict"; | ||
} | ||
function statusFromError(err) { | ||
// to get status, we requires err['metadata']['grpc-status-details-bin'] | ||
function statusFromError(err // error with status code and status message | ||
) { | ||
// to parse status details, we requires err['metadata']['grpc-status-details-bin'] | ||
if (!("metadata" in err && | ||
"grpc-status-details-bin" in err["metadata"] && | ||
typeof err.metadata["grpc-status-details-bin"] === "string")) { | ||
// if the error does not contain status, return null | ||
// if the error does not contain details bin, check if err contains status only | ||
if (("code" in err && typeof err.code === "number") || | ||
("message" in err && typeof err.message === "string")) { | ||
// if so, return the status and an empty array for details | ||
const st = new status_pb_1.Status(); | ||
st.setCode(err.code); | ||
st.setMessage(err.message); | ||
st.setDetailsList([]); | ||
return [st, []]; | ||
} | ||
// if the error does not have any information, return null | ||
return [null, null]; | ||
@@ -56,0 +67,0 @@ } |
{ | ||
"name": "grpc-web-error-details", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Utility function for deserializing `grpc-status-details-bin` metadata on grpc-web", | ||
@@ -35,3 +35,3 @@ "license": "MIT", | ||
"genProto": "bash ./run-protoc.sh", | ||
"prepublish": "build" | ||
"prepare": "npm run build" | ||
}, | ||
@@ -38,0 +38,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117984
3096