Skip to content

Commit fe482d0

Browse files
committed
Changes while reviewing
1 parent eb08b27 commit fe482d0

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

rest.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env node
22

3+
import { createExpressError } from './controllers/utils.js'
4+
35
/**
46
* This module is used for any REST support functionality. It is used as middleware and so
57
* has access to the http module request and response objects, as well as next()
6-
* It is in charge of responding to the client.
7-
*
8-
* @author thehabes
8+
* It is in charge of responding to the client.
9+
*
10+
* @author thehabes
911
*/
1012

1113
/**
@@ -45,18 +47,20 @@ const validateContentType = function (req, res, next) {
4547
}
4648
const contentType = (req.get("Content-Type") ?? "").toLowerCase()
4749
if (!contentType) {
48-
res.statusMessage = `Missing Content-Type header.`
49-
res.status(415)
50-
return next(res)
50+
return next(createExpressError({
51+
statusCode: 415,
52+
statusMessage: `Missing Content-Type header.`
53+
}))
5154
}
5255
const mimeType = contentType.split(";")[0].trim()
5356
if (mimeType === "application/json" || mimeType === "application/ld+json") return next()
5457
const isSearchEndpoint = req.path.startsWith("/search")
5558
if (mimeType === "text/plain" && isSearchEndpoint) return next()
5659
const acceptedTypes = `"application/json" or "application/ld+json"${isSearchEndpoint ? ' or "text/plain"' : ''}`
57-
res.statusMessage = `Unsupported Content-Type: "${contentType}". This endpoint requires ${acceptedTypes}.`
58-
res.status(415)
59-
next(res)
60+
next(createExpressError({
61+
statusCode: 415,
62+
statusMessage: `Unsupported Content-Type: "${contentType}". This endpoint requires ${acceptedTypes}.`
63+
}))
6064
}
6165

6266
/**

0 commit comments

Comments
 (0)