Skip to content

Commit

Permalink
Request body that fail de-serialization cause TerminalError (#429)
Browse files Browse the repository at this point in the history
This commit makes sure that any deserialization issues
caused by a malformed payload result in a TerminalError.
  • Loading branch information
igalshilman authored Sep 4, 2024
1 parent 492ce1e commit 29f56a3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/restate-sdk/src/types/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
type Serde,
serde,
} from "@restatedev/restate-sdk-core";
import { TerminalError } from "./errors.js";

// ----------- rpc clients -------------------------------------------------------

Expand Down Expand Up @@ -480,7 +481,14 @@ export class HandlerWrapper {
}

async invoke(context: unknown, input: Uint8Array) {
const req = this.inputSerde.deserialize(input);
let req: unknown;
try {
req = this.inputSerde.deserialize(input);
} catch (e) {
throw new TerminalError(`Failed to deserialize input.`, {
cause: e,
});
}
const res: unknown = await this.handler(context, req);
return this.outputSerde.serialize(res);
}
Expand Down

0 comments on commit 29f56a3

Please sign in to comment.