Make sure db errors are always turned into the correct type