Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: helper for setting custom HTTP status code #254

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sdk/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ export class Metadata {
this.entries = entries;
}

/**
* If this metadata object is being returned as the metadata for an HTTP transcoded response, this will set the
* HTTP status code for the response.
*
* This will have no impact on gRPC responses.
*
* @param code The status code to set.
*/
setHttpStatusCode(code: number) {
if (code < 100 || code >= 600) {
throw new Error('Invalid HTTP status code: ' + code);
}
this.set('_akkasls-http-code', code.toString());
}

/**
* @returns CloudEvent subject value
* @deprecated Use cloudevent.subject instead.
Expand Down