Module: NSConnector::Errors

Defined in:
lib/ns_connector/errors.rb

Overview

A collection of useful, catchable, and usually netsuite related errors.

For a list of errors that can be returned and conditions for returning said errors, see #try_handle_response!

Defined Under Namespace

Classes: NSError

Constant Summary collapse

NotFound =

Not found

Class.new(NSError)
Conflict =

Some field has a unique constraint on it which has a duplicate

Class.new(NSError)
InvalidSearchFilter =

Usually a search run on an invalid field

Class.new(NSError)
CCProcessorError =

Credit card processing problems

Class.new(NSError)
BeginChunking =

Internal use

Class.new(NSError)
EndChunking =

Internal use

Class.new(NSError)
Unknown =

Unknown errors should still have a #code and #message that is useful. They are raised when we got a JSON error response from NetSuite that we simply don’t cater explicitly for.

Class.new(NSError)
WTF =

Complete garbage received

Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.try_handle_response!(response) ⇒ Object

Try and make a HTTP response from netsuite a nice error.

Arguments

A Net::HTTP response, should be a 400

Raises
NSConnector::Errors::NotFound

on a RCRD_DSNT_EXIST

NSConnector::Errors::InvalidSearchFilter

on a

SSS_INVALID_SRCH_FILTER

NSConnector::Errors::Conflict

on a *_ALREADY_EXISTS

NSConnector::Errors::Unknown

on any unhandled but parseable error

NSConnector::Errors::WTF

on complete garbage from netsuite

Returns

Shouldn’t return



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ns_connector/errors.rb', line 59

def self.try_handle_response! response
	error = JSON.parse(response.body)['error']
	case error['code']
	when 'RCRD_DSNT_EXIST'
		raise NotFound, error
	when 'SSS_INVALID_SRCH_FILTER'
		raise InvalidSearchFilter, error
	when 'CC_PROCESSOR_ERROR'
		raise CCProcessorError
	when /_ALREADY_EXISTS$/
		raise Conflict, error
	else
		case error['message']
		when 'CHUNKY_MONKEY'
			raise BeginChunking, error
		when 'NO_MORE_CHUNKS'
			raise EndChunking, error
		end
		raise Unknown, error
	end
rescue JSON::ParserError
	raise WTF, 'Unparseable response, expecting JSON. '\
		"HTTP #{response.code}: \n#{response.body}"
end