-
Notifications
You must be signed in to change notification settings - Fork 75
Description
Currently, when using version 3.1 to send emails (POST /v3.1/send), if the email address is invalid, the following error is raised:
NoMethodError: undefined method 'body' for an instance of String (NoMethodError)
At this line, a check is performed to determine if the error is related to an invalid email. When that's the case, the response body (a string) is returned. However, this return type (a string) does not match the expected type (Faraday::Response) at the caller site (here), which leads to the error.
I am not sure why this special handling for invalid emails was introduced, but what do you think about simply raising an error like its done for all other cases (see here) and letting the consumers handle it as they see fit? I am happy to open a MR with this change or any suggestion that you may find more appropriated to address the current error.
NoMethodError: undefined method 'body' for an instance of String (NoMethodError)
Yajl::Parser.parse(response.body)
^^^^^
from mailjet/resource.rb:287:in `save'
from mailjet/resource.rb:304:in `save!'
from mailjet/resource.rb:132:in `block in Mailjet::Resource::ClassMethods#create'
from <internal:kernel>:91:in `tap'
from mailjet/resource.rb:131:in `create'
from mailjet/mailer.rb:78:in `deliver!'
from mail/message.rb:2145:in `do_delivery'
from mail/message.rb:253:in `block in Mail::Message#deliver'
from action_mailer/base.rb:595:in `block in ActionMailer::Base.deliver_mail'
from active_support/notifications.rb:210:in `block in ActiveSupport::Notifications.instrument'
from active_support/notifications/instrumenter.rb:58:in `instrument'
from active_support/notifications.rb:210:in `ActiveSupport::Notifications.instrument'
from action_mailer/base.rb:593:in `ActionMailer::Base.deliver_mail'
from mail/message.rb:253:in `deliver'
from delegate.rb:87:in `method_missing'
from app/jobs/mailjet_templated_email_job.rb:16:in `send_email'
from app/jobs/base_email_job.rb:28:in `perform'
from active_job/execution.rb:68:in `block in ActiveJob::Execution#_perform_job'
from active_support/callbacks.rb:120:in `block in ActiveSupport::Callbacks#run_callbacks'
from semantic_logger/base.rb:190:in `block in SemanticLogger::Base#tagged'
from semantic_logger/semantic_logger.rb:319:in `SemanticLogger.fast_tag'
from semantic_logger/base.rb:197:in `tagged'
from datadog/tracing/contrib/active_job/log_injection.rb:13:in `block (2 levels) in Datadog::Tracing::Contrib::ActiveJob::LogInjection.included'
from active_support/callbacks.rb:129:in `instance_exec'
from active_support/callbacks.rb:129:in `block in ActiveSupport::Callbacks#run_callbacks'
from i18n.rb:353:in `with_locale'
from active_job/translation.rb:9:in `block (2 levels) in <module:Translation>'
from active_support/callbacks.rb:129:in `instance_exec'
from active_support/callbacks.rb:129:in `block in ActiveSupport::Callbacks#run_callbacks'
from active_support/core_ext/time/zones.rb:65:in `Time.use_zone'
from active_job/timezones.rb:9:in `block (2 levels) in <module:Timezones>'
from active_support/callbacks.rb:129:in `instance_exec'
from active_support/callbacks.rb:129:in `block in ActiveSupport::Callbacks#run_callbacks'
from active_support/callbacks.rb:140:in `run_callbacks'
from active_job/execution.rb:67:in `_perform_job'
from active_job/instrumentation.rb:32:in `_perform_job'
from active_job/execution.rb:51:in `perform_now'
from active_job/instrumentation.rb:26:in `block in ActiveJob::Instrumentation#perform_now'
from active_job/instrumentation.rb:40:in `block in ActiveJob::Instrumentation#instrument'
from active_support/notifications.rb:210:in `block in ActiveSupport::Notifications.instrument'
from active_support/notifications/instrumenter.rb:58:in `instrument'
from active_support/notifications.rb:210:in `ActiveSupport::Notifications.instrument'
from active_job/instrumentation.rb:39:in `instrument'
from active_job/instrumentation.rb:26:in `perform_now'
from active_job/logging.rb:32:in `block in ActiveJob::Logging#perform_now'
from semantic_logger/base.rb:190:in `block in SemanticLogger::Base#tagged'
from semantic_logger/semantic_logger.rb:356:in `SemanticLogger.tagged'
from semantic_logger/base.rb:202:in `tagged'
from rails_semantic_logger/extensions/active_job/logging.rb:13:in `tag_logger'
from active_job/logging.rb:32:in `perform_now'
from sentry/rails/active_job.rb:10:in `perform_now'
from active_job/execution.rb:29:in `block in ActiveJob::Execution::ClassMethods#execute'
from active_support/callbacks.rb:120:in `block in ActiveSupport::Callbacks#run_callbacks'
from active_job/railtie.rb:95:in `block (4 levels) in <class:Railtie>'
from active_support/reloader.rb:77:in `block in ActiveSupport::Reloader.wrap'
from active_support/execution_wrapper.rb:91:in `ActiveSupport::ExecutionWrapper.wrap'
from active_support/reloader.rb:74:in `ActiveSupport::Reloader.wrap'
from active_job/railtie.rb:94:in `block (3 levels) in <class:Railtie>'
from active_support/callbacks.rb:129:in `instance_exec'
from active_support/callbacks.rb:129:in `block in ActiveSupport::Callbacks#run_callbacks'
from active_support/callbacks.rb:140:in `run_callbacks'
from active_job/execution.rb:27:in `execute'
from active_job/queue_adapters/resque_adapter.rb:47:in `ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper.perform'
from resque/job.rb:181:in `block (3 levels) in Resque::Job#perform'
from datadog/tracing/contrib/resque/resque_job.rb:56:in `block in Datadog::Tracing::Contrib::Resque::ResqueJob#around_perform0_datadog'
from datadog/tracing/trace_operation.rb:236:in `block in Datadog::Tracing::TraceOperation#measure'
from datadog/tracing/span_operation.rb:152:in `measure'
from datadog/tracing/trace_operation.rb:236:in `measure'
from datadog/tracing/tracer.rb:417:in `start_span'
from datadog/tracing/tracer.rb:166:in `block in Datadog::Tracing::Tracer#trace'
from datadog/tracing/context.rb:45:in `activate!'
from datadog/tracing/tracer.rb:165:in `trace'
from datadog/tracing.rb:29:in `Datadog::Tracing.trace'
from datadog/tracing/contrib/resque/resque_job.rb:37:in `around_perform0_datadog'
from resque/job.rb:180:in `block (2 levels) in Resque::Job#perform'
from resque/job.rb:188:in `perform'
from sentry/resque.rb:10:in `block in Sentry::Resque#perform'
from sentry/resque.rb:39:in `block in Sentry::Resque::SentryReporter.record'
from sentry/hub.rb:89:in `with_scope'
from sentry-ruby.rb:410:in `Sentry.with_scope'
from sentry/resque.rb:22:in `Sentry::Resque::SentryReporter.record'
from sentry/resque.rb:9:in `perform'
from datadog/tracing/contrib/resque/resque_job.rb:19:in `perform'
from resque/worker.rb:322:in `perform'
from resque/worker.rb:924:in `block in Resque::Worker#perform_with_fork'
from resque/worker.rb:922:in `fork'
from resque/worker.rb:922:in `perform_with_fork'
from resque/worker.rb:278:in `work_one_job'
from resque/worker.rb:249:in `block in Resque::Worker#work'
from <internal:kernel>:168:in `loop'
from resque/worker.rb:246:in `work'
from resque/tasks.rb:20:in `block (2 levels) in <main>'
from rake/task.rb:281:in `block in Rake::Task#execute'
from rake/task.rb:281:in `each'
from rake/task.rb:281:in `execute'
from datadog/tracing/contrib/rake/instrumentation.rb:32:in `execute'
from rake/task.rb:219:in `block in Rake::Task#invoke_with_call_chain'
from rake/task.rb:199:in `synchronize'
from rake/task.rb:199:in `invoke_with_call_chain'
from rake/task.rb:188:in `invoke'
from rake/application.rb:188:in `invoke_task'
from rake/application.rb:138:in `block (2 levels) in Rake::Application#top_level'
from rake/application.rb:138:in `each'
from rake/application.rb:138:in `block in Rake::Application#top_level'
from rake/application.rb:147:in `run_with_threads'
from rake/application.rb:132:in `top_level'
from rake/application.rb:83:in `block in Rake::Application#run'
from rake/application.rb:214:in `standard_exception_handling'
from rake/application.rb:80:in `run'
from /usr/local/bundle/gems/rake-13.3.0/exe/rake:27:in `<top (required)>'
from /usr/local/bundle/bin/rake:25:in `load'
from /usr/local/bundle/bin/rake:25:in `<main>'