diff --git a/lib/handlers/get.js b/lib/handlers/get.js index f4aed8ee..a35924ea 100644 --- a/lib/handlers/get.js +++ b/lib/handlers/get.js @@ -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) @@ -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)) } } diff --git a/test/integration/acl-oidc-test.js b/test/integration/acl-oidc-test.js index 8df0aa3b..1de13539 100644 --- a/test/integration/acl-oidc-test.js +++ b/test/integration/acl-oidc-test.js @@ -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() }) }) diff --git a/test/integration/formats-test.js b/test/integration/formats-test.js index 0fa43a60..4a8ef11b 100644 --- a/test/integration/formats-test.js +++ b/test/integration/formats-test.js @@ -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')