From b5a0a0c57b9a63e5b33b5a65a5390012d54987f8 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 19 Oct 2021 21:32:39 +0200 Subject: Fix JSON parsing --- src/services/postDatabase.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/services/postDatabase.ts') diff --git a/src/services/postDatabase.ts b/src/services/postDatabase.ts index a782af8..0fa741b 100644 --- a/src/services/postDatabase.ts +++ b/src/services/postDatabase.ts @@ -36,7 +36,12 @@ export class PostDatabase { } const fileContent = await fs.readFile(this.filePath, "utf8"); - const entries = t.array(PostDatabaseEntryC).decode(fileContent); + const entries = f.function.pipe( + fileContent, + f.json.parse, + f.either.mapLeft(() => []), + f.either.chain(t.array(PostDatabaseEntryC).decode) + ); if (f.either.isRight(entries)) { this.entries = this.max ? entries.right.slice(-1 * this.max) : entries.right; -- cgit v1.2.3-70-g09d2