handle mysql errors gracefully