Answer the question
In order to leave comments, you need to log in
How to catch postgres error?
Hello! Is there any way to catch the postgres error
ActiveRecord::StatementInvalid (PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8": 0xdf 0xd4
Answer the question
In order to leave comments, you need to log in
IMHO, errors at the DB level should not fall. The database is the last frontier, and the occurrence of errors at its level is a miscalculation in the application logic. Why not use validations?
In the controller method:
begin
# здесь находится AR запрос ...
rescue ActiveRecord::StatementInvalid => e
render( json: { message: "ActiveRecord::StatementInvalid error: #{e.message}" }, status: :bad_request )
return
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question