Skip to content

Commit a1154c6

Browse files
committed
Error redo
1 parent 6d0817f commit a1154c6

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

db-controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,7 @@ async function newTreePrime(obj) {
15741574

15751575
/**
15761576
*
1577-
* @param {Object} update `message` and `status` for creating a custom Error
1578-
* @param {Error} originalError `source` for tracing this Error
1577+
* @param {Object} err An object with `statusMessage` and `statusCode` for error reporting.
15791578
* @returns Error for use in Express.next(err)
15801579
*/
15811580
function createExpressError(err) {

rest.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ const checkPatchOverrideSupport = function (req, res) {
2929
* REST is all about communication. The response code and the textual body are particular.
3030
* RERUM is all about being clear. It will build custom responses sometimes for certain scenarios, will remaining RESTful.
3131
*
32-
* Note that the res upstream from this has been converted into err. res will not have what you are looking for, check err instead.
32+
* You have likely reached this with a next(createExpressError(err)) call. End here and send the error.
3333
*/
3434
const messenger = function (err, req, res, next) {
3535
if (res.headersSent) {
3636
next(err)
3737
return
3838
}
3939
let error = {}
40-
error.message = err.statusMessage ?? err.message ?? res.statusMessage ?? res.message ?? ``
41-
error.status = err.statusCode ?? res.statusCode ?? 500
40+
error.message = err.statusMessage ?? err.message ?? ``
41+
error.status = err.statusCode ?? 500
4242
if (error.status === 401) {
4343
//Special handler for token errors from the oauth module
4444
//Token errors come through with a message that we want. That message is in the error's WWW-Authenticate header
@@ -47,7 +47,6 @@ const messenger = function (err, req, res, next) {
4747
error.message += err.headers["WWW-Authenticate"]
4848
}
4949
}
50-
let genericMessage = ""
5150
let token = req.header("Authorization")
5251
if(token && !token.startsWith("Bearer ")){
5352
error.message +=`
@@ -96,7 +95,7 @@ The requested web page or resource could not be found.`
9695
// These are all handled in api-routes.js already.
9796
break
9897
case 409:
99-
// These are all handled in db-controller createExpressError() already.
98+
// These are all handled in db-controller.js already.
10099
break
101100
case 503:
102101
//RERUM is down or readonly. Handled upstream.
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import { jest } from "@jest/globals"
2+
import dotenv from "dotenv"
3+
dotenv.config()
24
import controller from '../../db-controller.js'
35

46
it("Functional '@id-id' negotiation on objects returned.", async () => {
57
let negotiate = {
68
"@context": "http://iiif.io/api/presentation/3/context.json",
79
"_id": "example",
8-
"@id": "https://store.rerum.io/v1/id/example",
10+
"@id": `${process.env.RERUM_ID_PREFIX}example`,
911
"test": "item"
1012
}
1113
negotiate = controller.idNegotiation(negotiate)
1214
expect(negotiate._id).toBeUndefined()
1315
expect(negotiate["@id"]).toBeUndefined()
14-
expect(negotiate.id).toBe("https://store.rerum.io/v1/id/example")
16+
expect(negotiate.id).toBe(`${process.env.RERUM_ID_PREFIX}example`)
1517
expect(negotiate.test).toBe("item")
1618

1719
let nonegotiate = {
1820
"@context":"http://example.org/context.json",
1921
"_id": "example",
20-
"@id": "https://store.rerum.io/v1/id/example",
22+
"@id": `${process.env.RERUM_ID_PREFIX}example`,
2123
"id": "test_example",
2224
"test":"item"
2325
}
2426
nonegotiate = controller.idNegotiation(nonegotiate)
2527
expect(nonegotiate._id).toBeUndefined()
26-
expect(nonegotiate["@id"]).toBe("https://store.rerum.io/v1/id/example")
28+
expect(nonegotiate["@id"]).toBe(`${process.env.RERUM_ID_PREFIX}example`)
2729
expect(nonegotiate.id).toBe("test_example")
2830
expect(nonegotiate.test).toBe("item")
2931
})

0 commit comments

Comments
 (0)