Skip to content

Commit d10348c

Browse files
committed
Responding to comments
1 parent 31588b6 commit d10348c

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/v1.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as grpc from "@grpc/grpc-js";
2-
import {} from "@grpc/grpc-js";
32
import { generateTestToken } from "./__utils__/helpers.js";
43
import { Struct } from "./authzedapi/google/protobuf/struct.js";
54
import { PreconnectServices, deadlineInterceptor } from "./util.js";

src/v1.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,19 @@ export function NewClientWithChannelCredentials(
403403
* @returns A google.protobuf.Struct object.
404404
*/
405405
export function createStructFromObject(data: JsonObject): ImportedPbStruct {
406-
if (data === null || typeof data !== "object" || Array.isArray(data)) {
407-
// Or handle this case as per library's error handling philosophy
408-
throw new Error(
409-
"Input data for createStructFromObject must be a non-null object.",
410-
);
406+
try {
407+
return ImportedPbStruct.fromJson(data);
408+
} catch (error) {
409+
if (
410+
error instanceof Error &&
411+
error.message.includes("Unable to parse message google.protobuf.Struct from JSON")
412+
) {
413+
throw new Error(
414+
"Input data for createStructFromObject must be a non-null object.",
415+
);
416+
}
417+
throw error;
411418
}
412-
return ImportedPbStruct.fromJson(data);
413419
}
414420

415421
export * from "./authzedapi/authzed/api/v1/core.js";

0 commit comments

Comments
 (0)