module Mailstro module Middleware module Response class RaiseError < Faraday::Response::RaiseError def on_complete(env) case env[:status] when 401 raise Error::AuthorisationError.new("api_key not authorised", env) when 422 raise Error::ValidationError.new(env[:body][:errors]) when 500 raise Error::MailstroError.new(env[:body]) else super end end end end end end