Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Csarven fix/translation error not acceptable #1755

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Loading