Customize default error messages

Customize default error messages

nipunafexconnipunafexcon Posts: 2Questions: 2Answers: 0
edited August 24 in Free community support

How do i change error response coming from server and show different messages based on different scenarios.
Example: When saving data,if it returns false, it will show

A system error has occurred (More information).

How do we customize this?

This question has an accepted answers - jump to answer

Answers

  • hotswaphotswap Posts: 6Questions: 1Answers: 1
    Answer ✓

    Hi,

    With this method, all errors are automatically intercepted but you can also customize each error as appropriate.

    Hope this help!

    ajax:
    {
        url: 'Your url',
        type: 'POST',
        data:
        {
            // Your data
        },
        
        beforeSend: function(jqXHR)
        {
            // Do something before send
        },
        
        error: function(jqXHR, textStatus, errorThrown)
        {
            // Note: You can use "textStatus" to describe the error.
            // Custom
            switch(jqXHR.status)
            {
                case 404:
                    alert('Requested page not found. [404]');
                break;
                
                case 500:
                    alert('Internal Server Error [500]');
                break;
                
                default:
                    alert('Unexpected unknow error');
                break:
            }
            
            // Global
            if (jqXHR.status != 0)
            {
                alert('A system error has occurred (More information).');
                // Or you can invoke modal bootstrap rather than a java alert.    
            }
        },
        
        complete: function(jqXHR)
        {
            // Do something when complete
        }
    }
    
Sign In or Register to comment.