Skip to content

Commit 7c8ccc6

Browse files
authored
Merge pull request #1755 from nodeSolidServer/csarven-fix/translation-error-not-acceptable
Csarven fix/translation error not acceptable
2 parents 032df34 + 69ef87c commit 7c8ccc6

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

lib/handlers/get.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ 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) {
119+
if (!possibleRDFType || !RDFs.includes(contentType)) { // possibleRDFType defaults to text/turtle
120120
return next(error(406, 'Cannot serve requested type: ' + contentType))
121121
}
122-
123122
try {
124123
// Translate from the contentType found to the possibleRDFType desired
125124
const data = await translate(stream, baseUri, contentType, possibleRDFType)
@@ -128,8 +127,8 @@ async function handler (req, res, next) {
128127
res.send(data)
129128
return next()
130129
} catch (err) {
131-
debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 500 + ' ' + err.message)
132-
return next(error(500, 'Error translating between RDF formats'))
130+
debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message)
131+
return next(error(500, 'Cannot serve requested type: ' + requestedType))
133132
}
134133
}
135134

test/integration/acl-oidc-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -775,12 +775,12 @@ describe('ACL with WebID+OIDC over HTTP', function () {
775775
done()
776776
})
777777
})
778-
it('We should have a 500 with invalid group listings', function (done) {
778+
it('We should have a 406 with invalid group listings', function (done) {
779779
const options = createOptions('/group/test-folder/some-other-file.txt', 'user2')
780780

781781
request.get(options, function (error, response, body) {
782782
assert.equal(error, null)
783-
assert.equal(response.statusCode, 500)
783+
assert.equal(response.statusCode, 406)
784784
done()
785785
})
786786
})

test/integration/formats-test.js

+15
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)