http#STATUS_CODES TypeScript Examples
The following examples show how to use
http#STATUS_CODES.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From big-web-quiz with Apache License 2.0 | 7 votes |
export function abortHandshake(
socket: Socket,
code: number,
message: string = STATUS_CODES[code] || 'unknown',
headers: { [headerName: string]: string } = {},
) {
if (socket.writable) {
headers = {
Connection: 'close',
'Content-type': 'text/html',
'Content-Length': Buffer.byteLength(message).toString(),
...headers,
};
socket.write(
`HTTP/1.1 ${code} ${STATUS_CODES[code]}\r\n` +
Object.keys(headers)
.map(h => `${h}: ${headers[h]}`)
.join('\r\n') +
'\r\n\r\n' +
message,
);
}
socket.destroy();
}
Example #2
Source File: bad-request.filter.ts From bank-server with MIT License | 6 votes |
catch(exception: BadRequestException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
let statusCode = exception.getStatus();
const r = <any>exception.getResponse();
if (_.isArray(r.message) && r.message[0] instanceof ValidationError) {
statusCode = HttpStatus.UNPROCESSABLE_ENTITY;
const validationErrors = <ValidationError[]>r.message;
this._validationFilter(validationErrors);
}
r.statusCode = statusCode;
r.error = STATUS_CODES[statusCode];
response.status(statusCode).json(r);
}
Example #3
Source File: query-failed.filter.ts From bank-server with MIT License | 6 votes |
catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const errorMessage = ConstraintErrors[exception.constraint];
const status =
exception.constraint && exception.constraint.startsWith('UQ')
? HttpStatus.CONFLICT
: HttpStatus.INTERNAL_SERVER_ERROR;
response.status(status).json({
statusCode: status,
error: STATUS_CODES[status],
message: errorMessage,
});
}
Example #4
Source File: mock-server.ts From amman with Apache License 2.0 | 5 votes |
function fail(res: ServerResponse, msg: string, statusCode = 422) {
writeStatusHead(res, statusCode)
res.end(`${STATUS_CODES[statusCode]}: ${msg}`)
}
Example #5
Source File: [id].tsx From livepeer-com with MIT License | 4 votes |
WebhookDetail = () => {
useLoggedIn();
const { user, getWebhook, deleteWebhook, updateWebhook } = useApi();
const [deleting, setDeleting] = useState(false);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const router = useRouter();
const dialogState = useToggleState();
const { id } = router.query;
const fetcher = useCallback(async () => {
const webhook = await getWebhook(id);
return webhook;
}, [id]);
const { data } = useQuery([id], () => fetcher());
const queryClient = useQueryClient();
const invalidateQuery = useCallback(() => {
return queryClient.invalidateQueries(id);
}, [queryClient, id]);
return !user ? null : (
<Layout
id="developers/webhooks"
breadcrumbs={[
{ title: "Developers" },
{ title: "Webhooks", href: "/dashboard/developers/webhooks" },
{ title: data?.name },
]}>
<Box css={{ p: "$6" }}>
<Box css={{ mb: "$8" }}>
{data && (
<Box
css={{
borderRadius: 6,
border: "1px solid $colors$primary7",
}}>
<Flex
css={{
p: "$3",
width: "100%",
borderBottom: "1px solid $colors$primary7",
gap: "$3",
fd: "row",
ai: "center",
jc: "space-between",
}}>
<Heading
size="2"
css={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
width: "100%",
ai: "flex-start",
}}>
{data.url}
</Heading>
<Flex css={{ ai: "flex-end", fg: "0", fs: "0", pl: "$3" }}>
<AlertDialog open={deleteDialogOpen}>
<Button
onClick={() => {
setDeleteDialogOpen(true);
}}
size="2"
css={{ mr: "$2", display: "flex", ai: "center" }}
variant="red">
<StyledCross />
Delete
</Button>
<AlertDialogContent
css={{ maxWidth: 450, px: "$5", pt: "$4", pb: "$4" }}>
<AlertDialogTitle asChild>
<Heading size="1">Delete Webhook</Heading>
</AlertDialogTitle>
<AlertDialogDescription asChild>
<Text
size="3"
variant="gray"
css={{ mt: "$2", lineHeight: "22px" }}>
Are you sure you want to delete this webhook?
</Text>
</AlertDialogDescription>
<Flex css={{ jc: "flex-end", gap: "$2", mt: "$5" }}>
<Button
onClick={() => setDeleteDialogOpen(false)}
size="2"
ghost>
Cancel
</Button>
<AlertDialogAction asChild>
<Button
size="2"
disabled={deleting}
onClick={async () => {
setDeleting(true);
await deleteWebhook(data.id);
await invalidateQuery();
setDeleting(false);
setDeleteDialogOpen(false);
router.push("/dashboard/developers/webhooks");
}}
variant="red">
{deleting && (
<Spinner
css={{
width: 16,
height: 16,
mr: "$2",
}}
/>
)}
Delete
</Button>
</AlertDialogAction>
</Flex>
</AlertDialogContent>
</AlertDialog>
<WebhookDialog
button={
<Button
size="2"
css={{ display: "flex", ai: "center" }}
onClick={() => dialogState.onToggle()}>
<StyledPencil />
Update details
</Button>
}
webhook={data}
action={Action.Update}
isOpen={dialogState.on}
onOpenChange={dialogState.onToggle}
onSubmit={async ({ events, name, url, sharedSecret }) => {
delete data.event; // remove deprecated field before updating
await updateWebhook(data.id, {
...data,
events: events ? events : data.events,
name: name ? name : data.name,
url: url ? url : data.url,
sharedSecret: sharedSecret ?? data.sharedSecret,
});
await invalidateQuery();
}}
/>
</Flex>
</Flex>
<Box
css={{
display: "grid",
gridTemplateColumns: "12em auto",
width: "100%",
fontSize: "$2",
position: "relative",
p: "$3",
borderBottomLeftRadius: 6,
borderBottomRightRadius: 6,
backgroundColor: "$panel",
}}>
<Cell variant="gray">URL</Cell>
<Cell>{data.url}</Cell>
<Cell variant="gray">Name</Cell>
<Cell>{data.name}</Cell>
<Cell variant="gray">Secret</Cell>
<Cell>{data.sharedSecret}</Cell>
<Cell variant="gray">Created</Cell>
<Cell>{format(data.createdAt, "MMMM dd, yyyy h:mm a")}</Cell>
<Cell variant="gray">Event types</Cell>
<Cell css={{ display: "flex", fw: "wrap" }}>
{data.events.map((e) => (
<Badge
variant="primary"
size="2"
css={{ fontWeight: 600, mr: "$1", mb: "$1" }}>
{e}
</Badge>
))}
</Cell>
<Cell variant="gray">Last trigger</Cell>
<Cell>
{data.status
? format(
data.status?.lastTriggeredAt,
"MMMM dd, yyyy h:mm:ss a"
)
: "Never"}
</Cell>
<Cell variant="gray">Last failure</Cell>
<Cell>
{!data.status
? "Never"
: data.status.lastFailure
? format(
data.status.lastFailure.timestamp,
"MMMM dd, yyyy h:mm:ss a"
)
: "Never"}
</Cell>
{data.status ? (
data.status.lastFailure?.statusCode ? (
<>
<Cell variant="gray">Error Status Code</Cell>
<Cell>{`${data.status.lastFailure.statusCode}
${
STATUS_CODES[data.status.lastFailure.statusCode]
}`}</Cell>
</>
) : data.status.lastFailure ? (
<>
<Cell variant="gray">Error message</Cell>
<Cell
css={{
fontFamily: "monospace",
}}>
{data.status.lastFailure.error ?? "unknown"}
</Cell>
</>
) : (
""
)
) : (
""
)}
{data.status?.lastFailure?.response ? (
<>
<Cell variant="gray">Error response</Cell>
<Cell
css={{
fontFamily: "monospace",
}}>
{data.status.lastFailure.response}
</Cell>
</>
) : (
""
)}
</Box>
</Box>
)}
</Box>
</Box>
</Layout>
);
}