Customizing an error message returned by the database engine

Customizing an error message returned by the database engine

Yves HEBERTYves HEBERT Posts: 10Questions: 4Answers: 0

Is it possible to customize an error message that comes from the low data and is displayed on the "editor" form after submitting a deletion request such as (this message is justified):

SQLSTATE [23000]: [Microsoft] [ODBC Driver 13 for SQL Server] [SQL Server] The statement DELETE conflicted with the REFERENCE constraint "FK_xxx_yyy". The conflict occurred in database "DB", table "dbo.xxx", column 'id'.

How to use postSumi or submitSuccess to modify the message?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    Answer ✓

    Generally I would say don't modify that method. Use validation to confirm that the delete can be done before an SQL error is triggered.

    However, you could use postSubmit like this:

    editor.on('postSubmit', function (e, json) {
      if ( json.error && json.error.indexOf('The statement DELETE conflicted with the REFERENCE constraint') !== -1 ) {
        json.error = "Cannot delete";
      }
    });
    

    Allan

  • Yves HEBERTYves HEBERT Posts: 10Questions: 4Answers: 0

    Ideal solution in my context,

    Thank you

This discussion has been closed.