mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Resolve duplicate error message and no trailing newline
* fix: Resolves duplicate error message * test: Add trailing newline on error test
This commit is contained in:
parent
99464d9a95
commit
a7fa61ab2f
@ -27,7 +27,9 @@ export class BasicResponseWriter extends ResponseWriter {
|
|||||||
}
|
}
|
||||||
input.response.setHeader('content-type', 'text/plain');
|
input.response.setHeader('content-type', 'text/plain');
|
||||||
input.response.writeHead(code);
|
input.response.writeHead(code);
|
||||||
input.response.end(`${input.result.name}: ${input.result.message}\n${input.result.stack}`);
|
input.response.end(typeof input.result.stack === 'string' ?
|
||||||
|
`${input.result.stack}\n` :
|
||||||
|
`${input.result.name}: ${input.result.message}\n`);
|
||||||
} else {
|
} else {
|
||||||
input.response.setHeader('location', input.result.identifier.path);
|
input.response.setHeader('location', input.result.identifier.path);
|
||||||
if (input.result.body) {
|
if (input.result.body) {
|
||||||
|
@ -81,4 +81,19 @@ describe('A BasicResponseWriter', (): void => {
|
|||||||
expect(response._getStatusCode()).toBe(error.statusCode);
|
expect(response._getStatusCode()).toBe(error.statusCode);
|
||||||
expect(response._getData()).toMatch('UnsupportedHttpError: error');
|
expect(response._getData()).toMatch('UnsupportedHttpError: error');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('responds with the error name and message when no stack trace is lazily generated.', async(): Promise<void> => {
|
||||||
|
const error = new Error('error');
|
||||||
|
error.stack = undefined;
|
||||||
|
await writer.handle({ response, result: error });
|
||||||
|
expect(response._isEndCalled()).toBeTruthy();
|
||||||
|
expect(response._getStatusCode()).toBe(500);
|
||||||
|
expect(response._getData()).toMatch('Error: error');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ends its response with a newline if there is an error.', async(): Promise<void> => {
|
||||||
|
await writer.handle({ response, result: new Error('error') });
|
||||||
|
expect(response._isEndCalled()).toBeTruthy();
|
||||||
|
expect(response._getData().endsWith('\n')).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user