Skip to content

Commit

Permalink
fix(middleware): properly format 406 response
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Mar 3, 2024
1 parent 7d060ed commit a168133
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,19 @@ const handleResponse = (context: ParameterizedContext<JsonApiState>): void => {

if (matchingTypes.length === 0) {
context.status = 406;
context.body = new JsonApiErrorBody({
status: "406",
code: "not_acceptable",
title: "Not Acceptable",
detail: "No valid accept types provided, you must accept application/vnd.api+json",
meta: appliedExtensions ? { appliedExtensions } : undefined,
});
context.set("Content-Type", contentTypeUtil.format({ type: "application/vnd.api+json" }));
context.body = {
jsonapi: { version: "1.1" },
errors: [
{
status: "406",
code: "not_acceptable",
title: "Not Acceptable",
detail: "No valid accept types provided, you must accept application/vnd.api+json",
meta: appliedExtensions ? { appliedExtensions } : undefined,
},
],
};

return;
}
Expand Down
File renamed without changes.

0 comments on commit a168133

Please sign in to comment.