@@ -4,19 +4,20 @@ module SendGrid
44 class Client
55 attr_accessor :api_user , :api_key , :protocol , :host , :port , :url , :endpoint ,
66 :user_agent
7- attr_writer :adapter , :conn
7+ attr_writer :adapter , :conn , :raise_exceptions
88
99 def initialize ( params = { } )
10- self . api_user = params . fetch ( :api_user , nil )
11- self . api_key = params . fetch ( :api_key , nil )
12- self . protocol = params . fetch ( :protocol , 'https' )
13- self . host = params . fetch ( :host , 'api.sendgrid.com' )
14- self . port = params . fetch ( :port , nil )
15- self . url = params . fetch ( :url , protocol + '://' + host + ( port ? ":#{ port } " : '' ) )
16- self . endpoint = params . fetch ( :endpoint , '/api/mail.send.json' )
17- self . adapter = params . fetch ( :adapter , adapter )
18- self . conn = params . fetch ( :conn , conn )
19- self . user_agent = params . fetch ( :user_agent , "sendgrid/#{ SendGrid ::VERSION } ;ruby" )
10+ self . api_user = params . fetch ( :api_user , nil )
11+ self . api_key = params . fetch ( :api_key , nil )
12+ self . protocol = params . fetch ( :protocol , 'https' )
13+ self . host = params . fetch ( :host , 'api.sendgrid.com' )
14+ self . port = params . fetch ( :port , nil )
15+ self . url = params . fetch ( :url , protocol + '://' + host + ( port ? ":#{ port } " : '' ) )
16+ self . endpoint = params . fetch ( :endpoint , '/api/mail.send.json' )
17+ self . adapter = params . fetch ( :adapter , adapter )
18+ self . conn = params . fetch ( :conn , conn )
19+ self . user_agent = params . fetch ( :user_agent , "sendgrid/#{ SendGrid ::VERSION } ;ruby" )
20+ self . raise_exceptions = params . fetch ( :raise_exceptions , true )
2021 yield self if block_given?
2122 end
2223
@@ -38,7 +39,7 @@ def send(mail)
3839 req . body = payload
3940 end
4041
41- fail SendGrid ::Exception , res . body if res . status != 200
42+ fail SendGrid ::Exception , res . body if raise_exceptions? && res . status != 200
4243
4344 SendGrid ::Response . new ( code : res . status , headers : res . headers , body : res . body )
4445 end
@@ -54,5 +55,9 @@ def conn
5455 def adapter
5556 @adapter ||= Faraday . default_adapter
5657 end
58+
59+ def raise_exceptions?
60+ @raise_exceptions
61+ end
5762 end
5863end
0 commit comments