From 3283d1f0113a4a276aeeb29658a3885fbbea6fdd Mon Sep 17 00:00:00 2001 From: Josh Crews Date: Tue, 16 Apr 2024 10:11:20 -0500 Subject: [PATCH] dont throw obtuse json parse error when rock returning an html page (#60) --- lib/rock_rms/parse_oj.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/rock_rms/parse_oj.rb b/lib/rock_rms/parse_oj.rb index 45c7657..6fd361a 100644 --- a/lib/rock_rms/parse_oj.rb +++ b/lib/rock_rms/parse_oj.rb @@ -5,6 +5,8 @@ class ParseOj < Faraday::Middleware def on_complete(env) if empty_body?(env[:body].strip) env[:body] = nil + elsif html_body?(env[:body]) + env[:body] = env[:body] else env[:body] = Oj.load(env[:body], mode: :compat) end @@ -12,6 +14,10 @@ def on_complete(env) private + def html_body?(body) + body.start_with?('') + end + def empty_body?(body) body.empty? && body == '' end