Module: SolidErrors::Frontend::Payload

Defined in:
lib/solid_errors/frontend/payload.rb

Overview

Parses the request body into Reports.

This is the trust boundary: the endpoint is unauthenticated by design (errors on the sign-in page are worth having), so malformed or hostile input has to produce an empty list rather than an exception.

Class Method Summary collapse

Class Method Details

.parse(body, limit: SolidErrors::Frontend.max_reports_per_request) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/solid_errors/frontend/payload.rb', line 12

def self.parse(body, limit: SolidErrors::Frontend.max_reports_per_request)
  parsed = JSON.parse(body.to_s)
  return [] unless parsed.is_a?(Hash)

  reports = parsed["reports"]
  return [] unless reports.is_a?(Array)

  reports.first(limit).filter_map do |attributes|
    Report.from(attributes) if attributes.is_a?(Hash)
  end
rescue JSON::ParserError
  []
end