@@ -80,7 +80,17 @@ def self.send_request(path, q=nil)
80
80
if !@branch . nil? && !@branch . empty?
81
81
params [ "branch" ] = @branch
82
82
end
83
- ActiveSupport ::JSON . decode ( URI . open ( "#{ @host } #{ @api_version } #{ path } #{ query } " , params ) . read )
83
+ begin
84
+ ActiveSupport ::JSON . decode ( URI . open ( "#{ @host } #{ @api_version } #{ path } #{ query } " , params ) . read )
85
+ rescue OpenURI ::HTTPError => error
86
+ response = error . io
87
+ #response.status
88
+ # => ["503", "Service Unavailable"]
89
+ error_response = JSON . parse ( response . string )
90
+ error_status = { "status_code" => response . status [ 0 ] , "status_message" => response . status [ 1 ] }
91
+ error = error_response . merge ( error_status )
92
+ raise Contentstack ::Error . new ( error . to_s )
93
+ end
84
94
end
85
95
86
96
def self . send_preview_request ( path , q = nil )
@@ -99,7 +109,17 @@ def self.send_preview_request(path, q=nil)
99
109
if !@branch . nil? && !@branch . empty?
100
110
params [ "branch" ] = @branch
101
111
end
102
- ActiveSupport ::JSON . decode ( URI . open ( "#{ preview_host } #{ @api_version } #{ path } #{ query } " , params ) . read )
112
+ begin
113
+ ActiveSupport ::JSON . decode ( URI . open ( "#{ preview_host } #{ @api_version } #{ path } #{ query } " , params ) . read )
114
+ rescue OpenURI ::HTTPError => error
115
+ response = error . io
116
+ #response.status
117
+ # => ["503", "Service Unavailable"]
118
+ error_response = JSON . parse ( response . string )
119
+ error_status = { "status_code" => response . status [ 0 ] , "status_message" => response . status [ 1 ] }
120
+ error = error_response . merge ( error_status )
121
+ raise Contentstack ::Error . new ( error . to_s )
122
+ end
103
123
end
104
124
end
105
125
end
0 commit comments