[Nitro] How do I gracefully handle db error conditions either from .rb or .xhtml files?

Reid Thompson Reid.Thompson at ateb.com
Fri Aug 18 14:59:46 EDT 2006


OK, so a duplicate key constraint violation throws an error.  How do I
capture this( or any db error condition for that matter ) so that I can
gracefully inform the user of the violation and return them to the data
entry page w/o having the app dump the full debug content to the screen
ala....
Error
Path: /save_user
ERROR C23505 Mduplicate key violates unique constraint
"oguser_username_key" Fnbtinsert.c L249 R_bt_check_unique
Reload this page. Go to the referer or the home page. 
In file
'/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/connection.rb' : 

110: else
111: # TODO
112: end
113: end
114: 
115: raise errors.map{|e| e.field_values.join("\t") }.join("\n") unless
errors.empty?
116: 
117: result
118: end
119: 
120: DEFAULT_PORT = 5432
Stack Trace
/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/connection.rb:115:in `query'
/usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/postgres-compat.rb:33:in `exec'
(eval):7:in `og_insert'
/usr/lib/ruby/gems/1.8/gems/og-0.30.0/lib/og/store.rb:104:in `save'
/usr/lib/ruby/gems/1.8/gems/og-0.30.0/lib/og/entity.rb:125:in `create'
./controller.rb:28:in `save_user'
(eval):6:in `save_user_action'
/usr/lib/ruby/gems/1.8/gems/nitro-0.30.0/lib/nitro/render.rb:129:in
`render'
/usr/lib/ruby/gems/1.8/gems/nitro-0.30.0/lib/nitro/adapter/webrick.rb:223:in `do_POST'
/usr/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/lib/ruby/gems/1.8/gems/nitro-0.30.0/lib/nitro/adapter/webrick.rb:59:in `start'
/usr/lib/ruby/gems/1.8/gems/nitro-0.30.0/lib/nitro/server/runner.rb:343:in `invoke_server'
/usr/lib/ruby/gems/1.8/gems/nitro-0.30.0/lib/nitro/server/runner.rb:305:in `invoke'
/usr/lib/ruby/gems/1.8/gems/nitro-0.30.0/lib/nitro/server.rb:128:in
`run'
/usr/lib/ruby/gems/1.8/gems/nitro-0.30.0/lib/nitro.rb:78:in `start'
demo.rb:19
Request
Parameters: {"username"=>"rthompso", "first_name"=>"adsf ",
"last_name"=>"adsf", "e_mail"=>"dfdf at ateb.com"}

Cookies: {"nsid"=>"074fd7f694752cf295cd14ff8c0fed12"}

Headers:
SERVER_NAME => localhost
ACCEPT-CHARSET => ISO-8859-1,utf-8;q=0.7,*;q=0.7
ACCEPT-LANGUAGE => en-us,en;q=0.5
CONTENT_LENGTH => 72
PATH_INFO => /save_user
REMOTE_HOST => 127.0.0.1
HTTP_ACCEPT_ENCODING => gzip,deflate
HTTP_USER_AGENT => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.5)
Gecko/20060731 Ubuntu/dapper-security Firefox/1.5.0.5
ACCEPT => text/xml,application/xml,application/xhtml
+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
CONNECTION => keep-alive
SCRIPT_NAME => 
SERVER_PROTOCOL => HTTP/1.1
HTTP_ACCEPT_LANGUAGE => en-us,en;q=0.5
HTTP_HOST => localhost:9999
ACCEPT-ENCODING => gzip,deflate
REMOTE_ADDR => 127.0.0.1
SERVER_SOFTWARE => WEBrick/1.3.1 (Ruby/1.8.4/2005-12-24)
HTTP_KEEP_ALIVE => 300
USER-AGENT => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.5)
Gecko/20060731 Ubuntu/dapper-security Firefox/1.5.0.5
CONTENT-TYPE => application/x-www-form-urlencoded
CONTENT_TYPE => application/x-www-form-urlencoded
HTTP_REFERER => http://localhost:9999/add_user
CONTENT-LENGTH => 72
COOKIE => nsid=074fd7f694752cf295cd14ff8c0fed12
HTTP_COOKIE => nsid=074fd7f694752cf295cd14ff8c0fed12
HTTP_ACCEPT_CHARSET => ISO-8859-1,utf-8;q=0.7,*;q=0.7
REQUEST_URI => /save_user
REFERER => http://localhost:9999/add_user
SERVER_PORT => 9999
GATEWAY_INTERFACE => CGI/1.1
QUERY_STRING => 
REMOTE_USER => 
HOST => localhost:9999
HTTP_ACCEPT => text/xml,application/xml,application/xhtml
+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
KEEP-ALIVE => 300
REQUEST_METHOD => POST
HTTP_CONNECTION => keep-alive


Response
Headers: {"Content-Type"=>"text/html"}

Cookies: nil


Session
Values: {:FLASH=>{}}



Powered by Nitro version 0.30.0





More information about the Nitro-general mailing list