lib/api_response/processor/failure.rb in api-response-presenter-0.0.1 vs lib/api_response/processor/failure.rb in api-response-presenter-0.0.2
- old
+ new
@@ -30,11 +30,11 @@
@response_body ||= config.parser.new(response, config: config).call
end
def build_error_monad
status = config.default_status || prepare_status(response)
- error = config.default_error || response_body.fetch(:error, nil) || response_body
+ error = config.error_json ? response_body : build_error
error_key = config.default_error_key || response_body.fetch(:error_key, nil)
Failure({error: error, error_key: error_key, status: status})
end
@@ -55,9 +55,13 @@
if config.symbol_status && config.default_status.is_a?(Integer)
ApiResponse::Types::SYMBOL_TO_STATUS_CODE[config.default_status]
else
config.default_status
end
+ end
+
+ def build_error
+ config.default_error || response_body
end
end
end
end