On Monday, September 12, 2011 1:00:41 AM UTC-4, Noel Villamor wrote: > > If the db update failed in the regular controller I would assume that > a ticket page would appear. But what if the db update is in a callback > function? >
In that case, an error ticket will still be logged, and web2py will return the usual 500 error with the link to the ticket. However, nothing will happen on the client side unless you include some JS to handle such errors. For example, you might register a jQuery .ajaxError handler (http://api.jquery.com/ajaxError/). You should be careful about the message you flash, though -- it's possible that the record could update but another error occurs -- in that case, you don't want to flash a message saying the record did not update. > > @Anthony, it seems that a db update failure would cause the rest of > the callback code to be not executed and so the flash='failure' > message won't appear at all. > Yes, it depends on the reason for the failure. If, for example, you try to update with a record id that doesn't exist, you won't get an error -- it will just return 0 as the number of rows updated. If you want to catch particular database errors on the server side, I suppose you could do something like this: try: db(db.tbl.id==100).update(data='sampledata') flash='success' except IntegrityError, OperationalError: flash='failure' # possibly log this somehow # All other exceptions result in 500 error to be handled client side. Anthony