mardi 25 juillet 2023

Ruby Datetime Error no implicit conversion of nil into String

I am getting the error "TypeError: no implicit conversion of nil into String" in Datetime method (ruby) and I wonder why my code is not working accordingly if I already have exception implemented. Any explanation about this or how to get rid of it?

      def get_parsed_datetime(raw_payload)
        parse_datetime(raw_payload[:datetime])
      rescue ArgumentError
        raise Base::UnprocessableContentError, I18n.t('invalid_datetime_error')
      end

      def parse_datetime(datetime_value)
        {
          :date => Date.parse(datetime_value).strftime('%d/%m/%Y'),
          :hour => Time.parse(datetime_value).hour
        }
      end

Aucun commentaire:

Enregistrer un commentaire