From 73c81a00a10766900318d86640249d1b54c6b351 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 16:32:16 -0500 Subject: feat: specific error messages for fetch failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add HTTP status code checking (wttrin--extract-http-status) and pass error descriptions through the callback chain so users see "Location not found (HTTP 404)" or "Network error — check your connection" instead of the generic "Perhaps the location was misspelled?" for every failure. Also fix pre-existing bug where the condition-case error handler in extract-response-body killed an unrelated buffer after unwind-protect already cleaned up. 330 tests (was 307), all passing. --- tests/test-wttrin--extract-response-body.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/test-wttrin--extract-response-body.el') diff --git a/tests/test-wttrin--extract-response-body.el b/tests/test-wttrin--extract-response-body.el index 8dcf2d2..8e6686c 100644 --- a/tests/test-wttrin--extract-response-body.el +++ b/tests/test-wttrin--extract-response-body.el @@ -163,5 +163,33 @@ (should-not (buffer-live-p test-buffer)))) (should (string= "data" result)))) +;;; HTTP Status Code Handling +;; Note: wttrin--extract-response-body kills its buffer, so we capture +;; the result via a let binding before the buffer disappears. + +(ert-deftest test-wttrin--extract-response-body-error-404-returns-nil () + "A 404 response should return nil — the location doesn't exist." + (let (result) + (with-current-buffer (generate-new-buffer " *test-404*") + (insert "HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\n\r\nPage not found") + (setq result (wttrin--extract-response-body))) + (should-not result))) + +(ert-deftest test-wttrin--extract-response-body-error-500-returns-nil () + "A 500 response should return nil — the server is broken." + (let (result) + (with-current-buffer (generate-new-buffer " *test-500*") + (insert "HTTP/1.1 500 Internal Server Error\r\n\r\nServer error") + (setq result (wttrin--extract-response-body))) + (should-not result))) + +(ert-deftest test-wttrin--extract-response-body-normal-200-still-returns-body () + "A 200 response should still extract and return the body as before." + (let (result) + (with-current-buffer (generate-new-buffer " *test-200*") + (insert "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nWeather data here") + (setq result (wttrin--extract-response-body))) + (should (equal result "Weather data here")))) + (provide 'test-wttrin--extract-response-body) ;;; test-wttrin--extract-response-body.el ends here -- cgit v1.2.3