Skip to content

Commit

Permalink
non RDFs translation error
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgeoa committed Feb 5, 2024
1 parent 65b04bb commit 69ef87c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
9 changes: 4 additions & 5 deletions lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ 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 || !RDFs.includes(requestedType)) {
return next(error(406, 'Cannot serve requested type: ' + requestedType))
if (!possibleRDFType || !RDFs.includes(contentType)) { // possibleRDFType defaults to text/turtle
return next(error(406, 'Cannot serve requested type: ' + contentType))
}
try {
// Translate from the contentType found to the possibleRDFType desired
Expand All @@ -126,10 +126,9 @@ async function handler (req, res, next) {
res.setHeader('Content-Type', possibleRDFType)
res.send(data)
return next()
}
catch (err) {
} catch (err) {
debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message)
return next(error(406, 'Cannot serve requested type: ' + requestedType))
return next(error(500, 'Cannot serve requested type: ' + requestedType))
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/acl-oidc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,12 @@ describe('ACL with WebID+OIDC over HTTP', function () {
done()
})
})
it('We should have a 500 with invalid group listings', function (done) {
it('We should have a 406 with invalid group listings', function (done) {
const options = createOptions('/group/test-folder/some-other-file.txt', 'user2')

request.get(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 500)
assert.equal(response.statusCode, 406)
done()
})
})
Expand Down
15 changes: 15 additions & 0 deletions test/integration/formats-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ describe('formats', function () {
})
})

describe('text/plain (non RDFs)', function () {
it('Accept text/plain', function (done) {
server.get('/put-input.txt')
.set('accept', 'text/plain')
.expect('Content-type', 'text/plain')
.expect(200, done)
})
it('Accept text/turtle', function (done) {
server.get('/put-input.txt')
.set('accept', 'text/turtle')
.expect('Content-type', 'text/plain; charset=utf-8')
.expect(406, done)
})
})

describe('none', function () {
it('should return turtle document if no Accept header is set', function (done) {
server.get('/patch-5-initial.ttl')
Expand Down

0 comments on commit 69ef87c

Please sign in to comment.