Fixed db error not being caught correctly