mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 16:41:42 +00:00
feat: poder serializar las excepciones
This commit is contained in:
parent
71afdc16ae
commit
d3166f2c5a
2 changed files with 30 additions and 0 deletions
8
config/initializers/que.rb
Normal file
8
config/initializers/que.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
ActiveJob::Serializers.add_serializers ActiveJob::Serializers::ExceptionSerializer
|
||||||
|
|
||||||
|
# Notificar los errores
|
||||||
|
Que.error_notifier = proc do |error, job|
|
||||||
|
ExceptionNotifier.notify_exception(error, data: job)
|
||||||
|
end
|
22
lib/active_job/serializers/exception_serializer.rb
Normal file
22
lib/active_job/serializers/exception_serializer.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'json/add/exception'
|
||||||
|
|
||||||
|
module ActiveJob
|
||||||
|
module Serializers
|
||||||
|
class ExceptionSerializer < ObjectSerializer # :nodoc:
|
||||||
|
def serialize(ex)
|
||||||
|
super('value' => { 'class' => ex.class.name, 'exception' => ex.as_json })
|
||||||
|
end
|
||||||
|
|
||||||
|
def deserialize(hash)
|
||||||
|
hash.dig('value', 'class').constantize.json_create(hash.dig('value', 'exception'))
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def klass
|
||||||
|
Exception
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue