| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  | require_relative "devops_error" | 
					
						
							|  |  |  | class InvalidRecord < ::Devops::Exception::DevopsError | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 13:49:41 +03:00
										 |  |  |   # message could be a String or a hash like | 
					
						
							|  |  |  |   # { | 
					
						
							|  |  |  |   #   error_data: [{:key=>:provider, :message=>"Value can not be undefined"}] | 
					
						
							|  |  |  |   # } | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  |   def initialize msg | 
					
						
							|  |  |  |     if msg.is_a?(String) | 
					
						
							|  |  |  |       super(msg) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       @object = msg | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 13:49:41 +03:00
										 |  |  |   def message | 
					
						
							|  |  |  |     if @object | 
					
						
							|  |  |  |       messages = @object[:error_data].map do |error_item| | 
					
						
							|  |  |  |         "#{error_item[:key]}: #{error_item[:message]}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       "Following errors occured: \n#{messages.join('\n')}" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       super | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  |   def http_status | 
					
						
							|  |  |  |     400
 | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def http_body | 
					
						
							|  |  |  |     if @object.nil? | 
					
						
							|  |  |  |       super | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       JSON.pretty_generate(@object) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | end |