Class: ClientAuth::ErrorSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/client_auth/models/error_serializer.rb

Class Method Summary collapse

Class Method Details

.deserialize(data) ⇒ Object



9
10
11
12
13
# File 'lib/client_auth/models/error_serializer.rb', line 9

def self.deserialize(data)
  attrs = JSON.parse(data)['errors'].first
  klass = attrs['title'].constantize
  klass.new(attrs['status'], attrs['detail'])
end

.serialize(error) ⇒ Object



3
4
5
6
7
# File 'lib/client_auth/models/error_serializer.rb', line 3

def self.serialize(error)
  err = {status: error.status.to_s, title: error.title, detail: error.detail}
  serialization = {errors: [err]}
  serialization.to_json
end