Skip to content

Commit 69ef87c

Browse files
committed
non RDFs translation error
1 parent 65b04bb commit 69ef87c

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

lib/handlers/get.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ async function handler (req, res, next) {
116116

117117
// If it is not in our RDFs we can't even translate,
118118
// Sorry, we can't help
119-
if (!possibleRDFType || !RDFs.includes(requestedType)) {
120-
return next(error(406, 'Cannot serve requested type: ' + requestedType))
119+
if (!possibleRDFType || !RDFs.includes(contentType)) { // possibleRDFType defaults to text/turtle
120+
return next(error(406, 'Cannot serve requested type: ' + contentType))
121121
}
122122
try {
123123
// Translate from the contentType found to the possibleRDFType desired
@@ -126,10 +126,9 @@ async function handler (req, res, next) {
126126
res.setHeader('Content-Type', possibleRDFType)
127127
res.send(data)
128128
return next()
129-
}
130-
catch (err) {
129+
} catch (err) {
131130
debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message)
132-
return next(error(406, 'Cannot serve requested type: ' + requestedType))
131+
return next(error(500, 'Cannot serve requested type: ' + requestedType))
133132
}
134133
}
135134

test/integration/acl-oidc-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,12 @@ describe('ACL with WebID+OIDC over HTTP', function () {
742742
done()
743743
})
744744
})
745-
it('We should have a 500 with invalid group listings', function (done) {
745+
it('We should have a 406 with invalid group listings', function (done) {
746746
const options = createOptions('/group/test-folder/some-other-file.txt', 'user2')
747747

748748
request.get(options, function (error, response, body) {
749749
assert.equal(error, null)
750-
assert.equal(response.statusCode, 500)
750+
assert.equal(response.statusCode, 406)
751751
done()
752752
})
753753
})

test/integration/formats-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ describe('formats', function () {
108108
})
109109
})
110110

111+
describe('text/plain (non RDFs)', function () {
112+
it('Accept text/plain', function (done) {
113+
server.get('/put-input.txt')
114+
.set('accept', 'text/plain')
115+
.expect('Content-type', 'text/plain')
116+
.expect(200, done)
117+
})
118+
it('Accept text/turtle', function (done) {
119+
server.get('/put-input.txt')
120+
.set('accept', 'text/turtle')
121+
.expect('Content-type', 'text/plain; charset=utf-8')
122+
.expect(406, done)
123+
})
124+
})
125+
111126
describe('none', function () {
112127
it('should return turtle document if no Accept header is set', function (done) {
113128
server.get('/patch-5-initial.ttl')

0 commit comments

Comments
 (0)