Skip to content

Commit

Permalink
Merge pull request #1755 from nodeSolidServer/csarven-fix/translation…
Browse files Browse the repository at this point in the history
…-error-not-acceptable

Csarven fix/translation error not acceptable
  • Loading branch information
bourgeoa authored Feb 6, 2024
2 parents 032df34 + 69ef87c commit 7c8ccc6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ 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) {
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
const data = await translate(stream, baseUri, contentType, possibleRDFType)
Expand All @@ -128,8 +127,8 @@ async function handler (req, res, next) {
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'))
debug('error translating: ' + req.originalUrl + ' ' + contentType + ' -> ' + possibleRDFType + ' -- ' + 406 + ' ' + err.message)
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 @@ -775,12 +775,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 7c8ccc6

Please sign in to comment.