mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #4239 from overleaf/ae-html-error-message
Avoid using HTML responses as error messages GitOrigin-RevId: 4cb8df259f51ff351c6f22fa82c016068ff87880
This commit is contained in:
@@ -62,6 +62,80 @@ describe('fetchJSON', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles JSON error responses', async function () {
|
||||
fetchMock.get('/test', {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: { message: 'lorem ipsum' },
|
||||
})
|
||||
|
||||
return expect(getJSON('/test'))
|
||||
.to.eventually.be.rejectedWith('Internal Server Error')
|
||||
.and.be.an.instanceOf(FetchError)
|
||||
.to.nested.include({
|
||||
'data.message': 'lorem ipsum',
|
||||
})
|
||||
})
|
||||
|
||||
it('handles text error responses', async function () {
|
||||
fetchMock.get('/test', {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
},
|
||||
body: 'lorem ipsum',
|
||||
})
|
||||
|
||||
return expect(getJSON('/test'))
|
||||
.to.eventually.be.rejectedWith('Internal Server Error')
|
||||
.and.be.an.instanceOf(FetchError)
|
||||
.to.nested.include({
|
||||
'data.message': 'lorem ipsum',
|
||||
})
|
||||
})
|
||||
|
||||
it('handles text error responses sent as HTML', async function () {
|
||||
fetchMock.get('/test', {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'text/html',
|
||||
},
|
||||
body: 'lorem ipsum',
|
||||
})
|
||||
|
||||
return expect(getJSON('/test'))
|
||||
.to.eventually.be.rejectedWith('Internal Server Error')
|
||||
.and.be.an.instanceOf(FetchError)
|
||||
.to.nested.include({
|
||||
'data.message': 'lorem ipsum',
|
||||
})
|
||||
})
|
||||
|
||||
it('handles (ignores) HTML error responses sent as HTML', async function () {
|
||||
fetchMock.get('/test', {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'text/html',
|
||||
},
|
||||
body:
|
||||
'<!doctype html><html lang="en"><body><p>lorem ipsum</p></body></html>',
|
||||
})
|
||||
|
||||
const promise = getJSON('/test')
|
||||
|
||||
expect(promise)
|
||||
.to.eventually.be.rejectedWith('Internal Server Error')
|
||||
.and.be.an.instanceOf(FetchError)
|
||||
|
||||
try {
|
||||
await promise
|
||||
} catch (error) {
|
||||
expect(error.data).to.eql({})
|
||||
}
|
||||
})
|
||||
|
||||
it('handles POST requests', function () {
|
||||
const body = { example: true }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user