diff --git a/packages/server/modules/blobstorage/index.ts b/packages/server/modules/blobstorage/index.ts index 72a31eb94d..4936f60000 100644 --- a/packages/server/modules/blobstorage/index.ts +++ b/packages/server/modules/blobstorage/index.ts @@ -231,9 +231,12 @@ export const init: SpeckleModule['init'] = async (app) => { ) ) - const status = 400 - const response = 'Upload request error. The server logs may have more details.' - res.status(status).end(response) + res.contentType('application/json') + res + .status(400) + .end( + '{ "error": "Upload request error. The server logs may have more details." }' + ) }) req.pipe(busboy) diff --git a/packages/server/modules/core/rest/upload.ts b/packages/server/modules/core/rest/upload.ts index 2e59c11ab3..c0820168dc 100644 --- a/packages/server/modules/core/rest/upload.ts +++ b/packages/server/modules/core/rest/upload.ts @@ -423,7 +423,9 @@ export default (app: Router) => { 'Error during upload. Error occurred after {elapsedTimeMs}ms. Objects processed before error: {totalObjectsProcessed}. Error: {error}' ) if (!requestDropped) - res.status(400).end('Upload request error. The server logs have more details') + res + .status(400) + .end('{"error": "Upload request error. The server logs have more details."}') requestDropped = true }) diff --git a/packages/server/modules/fileuploads/index.ts b/packages/server/modules/fileuploads/index.ts index ddcebc7b9a..20696b19c6 100644 --- a/packages/server/modules/fileuploads/index.ts +++ b/packages/server/modules/fileuploads/index.ts @@ -118,6 +118,7 @@ export const init: SpeckleModule['init'] = async (app, isInitial) => { 'Error while uploading file.' ) } + res.contentType('application/json') res.status(response.statusCode).send(body) } ) diff --git a/packages/server/modules/fileuploads/tests/fileuploads.integration.spec.ts b/packages/server/modules/fileuploads/tests/fileuploads.integration.spec.ts index 1f72eaf0b2..2bfae6e6f7 100644 --- a/packages/server/modules/fileuploads/tests/fileuploads.integration.spec.ts +++ b/packages/server/modules/fileuploads/tests/fileuploads.integration.spec.ts @@ -189,7 +189,9 @@ describe('FileUploads @fileuploads', () => { .attach('test.ifc', require.resolve('@/readme.md'), 'test.ifc') expect(response.statusCode).to.equal(201) - expect(response.body).to.deep.equal({}) + expect(response.headers['content-type']).to.contain('application/json;') + expect(response.body.uploadResults).to.have.lengthOf(1) + expect(response.body.uploadResults[0].fileName).to.equal('test.ifc') const gqlResponse = await sendRequest(userOneToken, { query: `query ($streamId: String!) { stream(id: $streamId) { @@ -206,6 +208,9 @@ describe('FileUploads @fileuploads', () => { expect(noErrors(gqlResponse)) expect(gqlResponse.body.data.stream.fileUploads).to.have.lengthOf(1) expect(gqlResponse.body.data.stream.fileUploads[0].fileName).to.equal('test.ifc') + expect(gqlResponse.body.data.stream.fileUploads[0].id).to.equal( + response.body.uploadResults[0].blobId + ) //TODO expect subscription notification }) @@ -217,7 +222,11 @@ describe('FileUploads @fileuploads', () => { .attach('blob1', require.resolve('@/readme.md'), 'test1.ifc') .attach('blob2', require.resolve('@/package.json'), 'test2.ifc') expect(response.status).to.equal(201) - expect(response.body).to.deep.equal({}) + expect(response.headers['content-type']).to.contain('application/json;') + expect(response.body.uploadResults).to.have.lengthOf(2) + expect( + response.body.uploadResults.map((file: { fileName: string }) => file.fileName) + ).to.have.members(['test1.ifc', 'test2.ifc']) const gqlResponse = await sendRequest(userOneToken, { query: `query ($streamId: String!) { stream(id: $streamId) { @@ -241,6 +250,11 @@ describe('FileUploads @fileuploads', () => { (file: { fileName: string }) => file.fileName ) ).to.have.members(['test1.ifc', 'test2.ifc']) + expect( + gqlResponse.body.data.stream.fileUploads.map((file: { id: string }) => file.id) + ).to.have.members( + response.body.uploadResults.map((file: { blobId: string }) => file.blobId) + ) }) it('Returns 400 for bad form data', async () => { @@ -252,6 +266,8 @@ describe('FileUploads @fileuploads', () => { .send('--XXX\r\nCon') expect(response.status).to.equal(400) + expect(response.headers['content-type']).to.contain('application/json;') + expect(response.body.error).to.contain('Upload request error.') const gqlResponse = await sendRequest(userOneToken, { query: `query ($streamId: String!) { stream(id: $streamId) { @@ -278,8 +294,11 @@ describe('FileUploads @fileuploads', () => { .set('Authorization', `Bearer ${userOneToken}`) .attach('toolarge.ifc', Buffer.alloc(114_857_601, 'asdf'), 'toolarge.ifc') expect(response.status).to.equal(201) - - expect(response.body).to.deep.equal({}) + expect(response.headers['content-type']).to.contain('application/json;') + expect(response.body.uploadResults).to.have.lengthOf(1) + expect( + response.body.uploadResults.map((file: { fileName: string }) => file.fileName) + ).to.have.members(['toolarge.ifc']) const gqlResponse = await sendRequest(userOneToken, { query: `query ($streamId: String!) { stream(id: $streamId) { @@ -298,6 +317,9 @@ describe('FileUploads @fileuploads', () => { gqlResponse.body.data.stream.fileUploads, JSON.stringify(gqlResponse.body.data) ).to.have.lengthOf(1) + expect(gqlResponse.body.data.stream.fileUploads[0].id).to.equal( + response.body.uploadResults[0].blobId + ) //TODO expect no notifications })