Module: Gitlab::Fp::MessageSupport
- Included in:
- WebIde::Settings::Main
- Defined in:
- lib/gitlab/fp/message_support.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
Void.
Instance Method Summary collapse
Class Method Details
.extended(base) ⇒ Object
Returns void.
10 11 12 13 14 |
# File 'lib/gitlab/fp/message_support.rb', line 10 def self.extended(base) base.class_eval do private_class_method :generate_error_response_from_message end end |
Instance Method Details
#generate_error_response_from_message(message:, reason:) ⇒ Hash
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gitlab/fp/message_support.rb', line 19 def (message:, reason:) details_string = case .content in {} nil in { details: String => error_details } error_details in { details: Array => error_details } # NOTE: This join string intentionally has two spaces, so that it is a unique pattern which can be # split and parsed on the client if desired, to be presented in separate HTML elements. # We may eventually return an array of error messages, but this is a workaround for now. error_details.join(", ") in { errors: ActiveModel::Errors => errors } errors..join(", ") else raise "Unexpected message content, add a case to pattern match it and convert it to a String." end # NOTE: Safe navigation operator is used here to prevent a type error, because Module#name is a 'String | nil' = .class.name&.demodulize&.underscore&.humanize = details_string ? "#{}: #{details_string}" : { status: :error, message: , reason: reason } end |