Repository: solid/community-server (ts)

Issue:
Responses have no trailing newline
Responses should always end with a newline.
Otherwise, requests via curl look like this:

```text
rtaelman@zimmer2 ~ 🔷  curl -H 'Accept: text/turtlee' http://localhost:3000/
UnsupportedHttpError: No handler supports the given input: [Can only convert from application/ld+json,application/json,text/html,application/xhtml+xml,application/xml,text/xml,image/svg+xml,application/rdf+xml,application/n-quads,application/trig,application/n-triples,text/turtle,text/n3 to internal/quads., Can only convert from internal/quads to text/turtle.].
UnsupportedHttpError: No handler supports the given input: [Can only convert from application/ld+json,application/json,text/html,application/xhtml+xml,application/xml,text/xml,image/svg+xml,application/rdf+xml,application/n-quads,application/trig,application/n-triples,text/turtle,text/n3 to internal/quads., Can only convert from internal/quads to text/turtle.].
    at CompositeAsyncHandler.findHandler (/Users/rtaelman/Documents/UGent/nosync/community-server/src/util/CompositeAsyncHandler.js:77:15)
    at process._tickCallback X PUT -H "Content-Type: text/turtle" -d '<ex:s> <ex:p> <ex:o>' ick.js:68:7)rtaelman@zimmer2 ~ 🔷  curl -H 'Accept: text/turtlee' http://localhost:3000/
rtaelman@zimmer2 ~ 🔷  curl -H 'Accept: text/turtle' http://localhost:3000/
<ex:s> <ex:p> <ex:o>rtaelman@zimmer2 ~ 🔷
```
Duplicate error message
Some error messages seem to be repeated. For instance, with an invalid `PUT`, I would get:

```
UnsupportedHttpError: PUT operations require a body.
UnsupportedHttpError: PUT operations require a body.
    at PutOperationHandler.handle (/Users/ruben/Documents/UGent/Solid/solid-community-server/src/ldp/operations/PutOperationHandler.js:22:19)
    at CompositeAsyncHandler.handleSafe (/Users/ruben/Documents/UGent/Solid/solid-community-server/src/util/CompositeAsyncHandler.js:55:24)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async AuthenticatedLdpHandler.handle (/Users/ruben/Documents/UGent/Solid/solid-community-server/src/ldp/AuthenticatedLdpHandler.js:43:61)
    at async /Users/ruben/Documents/UGent/Solid/solid-community-server/src/server/ExpressHttpServer.js:34:17
```

Notice how the first line is there twice.
(Also, there is no newline at the end, but that's probably #83.)

Pull request description:
Resolves duplicate error message and no trailing newline
This PR:
- closes #120
- closes #83

Patch:
diff --git a/src/ldp/http/BasicResponseWriter.ts b/src/ldp/http/BasicResponseWriter.ts
index 569343c07..f62e5b3f6 100644
--- a/src/ldp/http/BasicResponseWriter.ts
+++ b/src/ldp/http/BasicResponseWriter.ts
@@ -27,7 +27,9 @@ export class BasicResponseWriter extends ResponseWriter {
       }
       input.response.setHeader('content-type', 'text/plain');
       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 {
       input.response.setHeader('location', input.result.identifier.path);
       if (input.result.body) {


Test patch:
diff --git a/test/unit/ldp/http/BasicResponseWriter.test.ts b/test/unit/ldp/http/BasicResponseWriter.test.ts
index 16a58d4f0..6796533a9 100644
--- a/test/unit/ldp/http/BasicResponseWriter.test.ts
+++ b/test/unit/ldp/http/BasicResponseWriter.test.ts
@@ -81,4 +81,19 @@ describe('A BasicResponseWriter', (): void => {
     expect(response._getStatusCode()).toBe(error.statusCode);
     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();
+  });
 });