Skip to content
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

Change translation error (500) to not acceptable (406) #1752

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@ async function handler (req, res, next) {

// If it is not in our RDFs we can't even translate,
// Sorry, we can't help
if (!possibleRDFType) {
return next(error(406, 'Cannot serve requested type: ' + contentType))
if (!possibleRDFType || !RDFs.includes(requestedType)) {
return next(error(406, 'Cannot serve requested type: ' + requestedType))
}

try {
// Translate from the contentType found to the possibleRDFType desired
const data = await translate(stream, baseUri, contentType, possibleRDFType)
debug(req.originalUrl + ' translating ' + contentType + ' -> ' + possibleRDFType)
res.setHeader('Content-Type', possibleRDFType)
res.send(data)
return next()
} catch (err) {
debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 500 + ' ' + err.message)
return next(error(500, 'Error translating between RDF formats'))
}
catch (err) {
debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message)
return next(error(406, 'Cannot serve requested type: ' + requestedType))
}
}

Expand Down
Loading