File: deserialization_error.rb

package info (click to toggle)
ruby-ms-rest 0.7.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 424 kB
  • sloc: ruby: 693; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
require 'json'

module MsRest
  #
  # Class which represents an error happening during deserialization of server response.
  #
  class DeserializationError < RestError

    # @return [String] the inner exception message.
    attr_accessor :exception_message

    # @return [String] the inner exception stacktrace.
    attr_accessor :exception_stacktrace

    # @return [MsRest::HttpOperationResponse] server response which client was unable to parse.
    attr_accessor :result

    #
    # Creates and initialize new instance of the DeserializationError class.
    # @param [String] message message the human readable description of error.
    # @param [String] exception_message the inner exception stacktrace.
    # @param [String] exception_stacktrace the inner exception stacktrace.
    # @param [MsRest::HttpOperationResponse] the request and response
    def initialize(msg, exception_message, exception_stacktrace, result)
      @msg = msg || self.class.name
      @exception_message = exception_message
      @exception_stacktrace = exception_stacktrace
      @result = result
    end
    
    def to_json(*a)
      {exception_message: exception_message, message: @msg,  stacktrace: exception_stacktrace, result: result}.to_json(*a)
    end
    
    def to_s
      JSON.pretty_generate(self)
    end

  end
end