From 36fc498038ed48e670240b99dc681e7c3bf2882f Mon Sep 17 00:00:00 2001 From: Jason Shiflet <387269+jshiflet@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:46:42 -0500 Subject: [PATCH] Added JSONDecoder to fix server crash when creating a to-do item in Home Assistant integration When creating a to-do item in Home Assistant, the ha-reminders-cli integration will error with one of two errors - Error during service call to todo.add_item: Failed to create reminder: Server disconnected - Error during service call to todo.add_item: Failed to create reminder: 502, message='Bad Gateway', url='https://[reverseProxyURL:port]/api/lists/[listName]/reminders' This also causes the reminders-api process to crash on the macOS device with the following backtrace: - NullDecoder.decode(...) CodableProtocols.swift:48 preconditionFailure("HBApplication.decoder has not been set") Adding middleware JSON decoder resolves the base crash problem and allows the to-do item to be created Co-authored-by: codex --- Sources/reminders-api/main.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/reminders-api/main.swift b/Sources/reminders-api/main.swift index 0c2e136..afca5e2 100644 --- a/Sources/reminders-api/main.swift +++ b/Sources/reminders-api/main.swift @@ -158,6 +158,11 @@ func startServer( app.encoder = jsonEncoder Logger.shared.debug("JSON encoder configured") + // Middleware for JSON response decoding + let jsonDecoder = JSONDecoder() + app.decoder = jsonDecoder + Logger.shared.debug("JSON decoder configured") + // Add CORS middleware app.middleware.add( HBCORSMiddleware(