-
Notifications
You must be signed in to change notification settings - Fork 4
Handle Bad Content-Type Headers RESTfully
#255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce0edc3
5b91d8d
2e014d7
1361b2e
1190481
c02fe7f
deeddc3
eb08b27
fe482d0
1a33fe1
0f5fa25
d88723a
bdbfdd5
7dcc4ff
525b47b
1c90464
2a7a67d
cbb475b
ff149f9
5337622
bfa3a28
f077138
232307d
2b7ea90
6a5dc5c
cbef6a6
a06037d
99522c4
e8dff8d
d194bbc
f9d4f41
555de09
e1d8b90
1a9c5b2
01d3359
8d106d0
0e6101d
c283859
f3cb69f
822b602
7d7046a
e298628
69a85f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| */ | ||
| import { newID, isValidID, db } from '../database/index.js' | ||
| import utils from '../utils.js' | ||
| import { createExpressError, getAgentClaim, parseDocumentID, getAllVersions, getAllDescendants } from './utils.js' | ||
| import { getAgentClaim, parseDocumentID, getAllVersions, getAllDescendants } from './utils.js' | ||
|
|
||
| /** | ||
| * Mark an object as deleted in the database. | ||
|
|
@@ -26,15 +26,15 @@ const deleteObj = async function(req, res, next) { | |
| try { | ||
| id = req.params["_id"] ?? parseDocumentID(JSON.parse(JSON.stringify(req.body))["@id"]) ?? parseDocumentID(JSON.parse(JSON.stringify(req.body))["id"]) | ||
| } catch(error){ | ||
| next(createExpressError(error)) | ||
| next(utils.createExpressError(error)) | ||
| return | ||
|
Comment on lines
26
to
30
|
||
| } | ||
| let agentRequestingDelete = getAgentClaim(req, next) | ||
| let originalObject | ||
| try { | ||
| originalObject = await db.findOne({"$or":[{"_id": id}, {"__rerum.slug": id}]}) | ||
| } catch (error) { | ||
| next(createExpressError(error)) | ||
| next(utils.createExpressError(error)) | ||
| return | ||
| } | ||
| if (null !== originalObject) { | ||
|
|
@@ -58,7 +58,7 @@ const deleteObj = async function(req, res, next) { | |
| }) | ||
| } | ||
| if (err.status) { | ||
| next(createExpressError(err)) | ||
| next(utils.createExpressError(err)) | ||
| return | ||
| } | ||
| let preserveID = safe_original["@id"] | ||
|
|
@@ -76,14 +76,14 @@ const deleteObj = async function(req, res, next) { | |
| try { | ||
| result = await db.replaceOne({ "_id": originalObject["_id"] }, deletedObject) | ||
| } catch (error) { | ||
| next(createExpressError(error)) | ||
| next(utils.createExpressError(error)) | ||
| return | ||
| } | ||
| if (result.modifiedCount === 0) { | ||
| //result didn't error out, the action was not performed. Sometimes, this is a neutral thing. Sometimes it is indicative of an error. | ||
| err.message = "The original object was not replaced with the deleted object in the database." | ||
| err.status = 500 | ||
| next(createExpressError(err)) | ||
| next(utils.createExpressError(err)) | ||
| return | ||
| } | ||
| //204 to say it is deleted and there is nothing in the body | ||
|
|
@@ -94,12 +94,12 @@ const deleteObj = async function(req, res, next) { | |
| //Not sure we can get here, as healHistoryTree might throw and error. | ||
| err.message = "The history tree for the object being deleted could not be mended." | ||
| err.status = 500 | ||
| next(createExpressError(err)) | ||
| next(utils.createExpressError(err)) | ||
| return | ||
| } | ||
| err.message = "No object with this id could be found in RERUM. Cannot delete." | ||
| err.status = 404 | ||
| next(createExpressError(err)) | ||
| next(utils.createExpressError(err)) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to just call out the functions we need here?