diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-11-30 13:14:42 +0100 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-11-30 13:14:42 +0100 |
commit | 8083c63617353e6df6652de0a985452ec145a3d9 (patch) | |
tree | bc6066e099f9070ba0651117a899e4dd8ac5d901 | |
parent | 8ebe9717e25cb578426ac452bcac3808671f3c24 (diff) | |
download | kronikarz-8083c63617353e6df6652de0a985452ec145a3d9.tar.gz kronikarz-8083c63617353e6df6652de0a985452ec145a3d9.zip |
Add error handling
-rw-r--r-- | lib/getPosts.ts | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/getPosts.ts b/lib/getPosts.ts index 1821f12..38e419c 100644 --- a/lib/getPosts.ts +++ b/lib/getPosts.ts @@ -4,27 +4,26 @@ import { readDir } from "./utils"; function getPosts(path: string): Array<Post> { let routesArray: Post[] = []; - try { - const years = readDir(`${path}`); - years.forEach((year: string) => { - const months = readDir(`${path}/${year}`); - months.forEach((month: string) => { - const days = readDir(`${path}/${year}/${month}`); - days.forEach((day: string) => { - const files = readDir(`${path}/${year}/${month}/${day}`); - files.forEach((file: string) => { - const fsRoute = `${path}/${year}/${month}/${day}/${file}`; - + const years = readDir(`${path}`); + years.forEach((year: string) => { + const months = readDir(`${path}/${year}`); + months.forEach((month: string) => { + const days = readDir(`${path}/${year}/${month}`); + days.forEach((day: string) => { + const files = readDir(`${path}/${year}/${month}/${day}`); + files.forEach((file: string) => { + const fsRoute = `${path}/${year}/${month}/${day}/${file}`; + try { const post = parsePost(fsRoute); - routesArray.push(post); - }); + } catch (err) { + console.log(err); + } }); }); }); - } finally { - return routesArray; - } + }); + return routesArray; } function createRoutesArray() { |