Skip to content

Commit

Permalink
dont throw obtuse json parse error when rock returning an html page (#60
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joshcrews authored Apr 16, 2024
1 parent 58315ef commit 3283d1f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rock_rms/parse_oj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ 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
end

private

def html_body?(body)
body.start_with?('<!DOCTYPE html>')
end

def empty_body?(body)
body.empty? && body == ''
end
Expand Down

0 comments on commit 3283d1f

Please sign in to comment.