module NSConnector::Errors

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!

Constants

BeginChunking

Internal use

CCProcessorError

Credit card processing problems

Conflict

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

EndChunking

Internal use

InvalidSearchFilter

Usually a search run on an invalid field

NotFound

Not found

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.

WTF

Complete garbage received

Public Class Methods

try_handle_response!(response) click to toggle source

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

# 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