Skip to content

Commit 5c9852f

Browse files
committed
Make init throws again and drop error handling
1 parent 065b61d commit 5c9852f

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

Sources/App/Controllers/BlogController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import Plot
1818
enum BlogController {
1919

2020
static func index(req: Request) async throws -> HTML {
21-
BlogActions.Index.View(path: req.url.path, model: BlogActions.Model()).document()
21+
BlogActions.Index.View(path: req.url.path, model: try BlogActions.Model()).document()
2222
}
2323

2424
static func indexFeed(req: Request) async throws -> RSS {
25-
let model = BlogActions.Model()
25+
let model = try BlogActions.Model()
2626
let items = model.summaries.map { summary -> Node <RSS.ChannelContext> in
2727
.item(
2828
.guid(
@@ -58,7 +58,7 @@ enum BlogController {
5858
guard let slug = req.parameters.get("slug")
5959
else { throw Abort(.notFound) }
6060

61-
let model = BlogActions.Model()
61+
let model = try BlogActions.Model()
6262
if let summary = model.summaries.first(where: { $0.slug == slug }) {
6363
return BlogActions.Show.View(path: req.url.path,
6464
model: summary).document()

Sources/App/Views/Blog/BlogActions+Model.swift

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ enum BlogActions {
3535

3636
var summaries: [PostSummary]
3737

38-
init() {
39-
do {
40-
let allSummaries = try Self.allSummaries()
41-
42-
summaries = if Current.environment() == .production {
43-
// Only "published" posts show in production.
44-
allSummaries.filter { $0.published }
45-
} else {
46-
// Show *everything* in development and on staging.
47-
allSummaries
48-
}
49-
} catch {
50-
Current.logger().report(error: error)
51-
summaries = []
38+
init() throws {
39+
let allSummaries = try Self.allSummaries()
40+
41+
summaries = if Current.environment() == .production {
42+
// Only "published" posts show in production.
43+
allSummaries.filter { $0.published }
44+
} else {
45+
// Show *everything* in development and on staging.
46+
allSummaries
5247
}
5348
}
5449

Tests/AppTests/BlogActionsModelTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BlogActionsModelTests: AppTestCase {
3838
Current.environment = { .development }
3939

4040
// MUT
41-
let summaries = BlogActions.Model().summaries
41+
let summaries = try BlogActions.Model().summaries
4242

4343
XCTAssertEqual(summaries.count, 2)
4444
XCTAssertEqual(summaries.map(\.slug), ["post-2", "post-1"])
@@ -59,7 +59,7 @@ class BlogActionsModelTests: AppTestCase {
5959
Current.environment = { .production }
6060

6161
// MUT
62-
let summaries = BlogActions.Model().summaries
62+
let summaries = try BlogActions.Model().summaries
6363

6464
// validate
6565
XCTAssertEqual(summaries.map(\.slug), ["post-1"])

0 commit comments

Comments
 (0)