Skip to content

Commit c900a32

Browse files
coddingtonbearphortx
authored andcommitted
Show distinct error message when content type is unspecified vs. specified but unknown; fixes #186.
1 parent c60a513 commit c900a32

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const ERROR_CODE_MESSAGES: Record<ErrorCode, string> = {
1313
"Authorization required. Find your API Key in the 'Local REST API' section of your Obsidian settings.",
1414
[ErrorCode.ContentTypeSpecificationRequired]:
1515
"Content-Type header required; this API accepts data in multiple content-types and you must indicate the content-type of your request body via the Content-Type header.",
16+
[ErrorCode.InvalidContentType]:
17+
"Unknown or invalid Content-Type specified in Content-Type header.",
1618
[ErrorCode.InvalidContentInsertionPositionValue]:
1719
"Invalid 'Content-Insertion-Position' header value.",
1820
[ErrorCode.InvalidContentForContentType]:

src/requestHandler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,11 +1114,16 @@ export default class RequestHandler {
11141114
};
11151115
const contentType = req.headers["content-type"];
11161116

1117-
if (!handlers[contentType]) {
1117+
if (!contentType) {
11181118
this.returnCannedResponse(res, {
11191119
errorCode: ErrorCode.ContentTypeSpecificationRequired,
11201120
});
11211121
return;
1122+
} else if (!handlers[contentType]) {
1123+
this.returnCannedResponse(res, {
1124+
errorCode: ErrorCode.InvalidContentType,
1125+
});
1126+
return;
11221127
}
11231128

11241129
try {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IPeriodicNoteSettings } from "obsidian-daily-notes-interface";
55
export enum ErrorCode {
66
TextContentEncodingRequired = 40010,
77
ContentTypeSpecificationRequired = 40011,
8+
InvalidContentType = 40012,
89
InvalidContentForContentType = 40015,
910
InvalidContentInsertionPositionValue = 40050,
1011
MissingHeadingHeader = 40051,

0 commit comments

Comments
 (0)