'Need help in calling a procedure inside the main procedure

I have created a table to fetch the error log from main Stored Procedure. I also have prepared Stored Procedure to fetch the error log.

I need to include the above SP inside the main SP to generate the error into error log table.. Trying to include the code(i.e. Function part) in the main Stored Procedure and run. Not sure how to include this in the try and catch block.

I guess the function part is incorrect. I need to correct it. Kindly guide me..

CREATE OR REPLACE TABLE t_error_log (
   order_log_id NUMBER AUTOINCREMENT START 1 INCREMENT 1
   , sp_name VARCHAR(16777216)
   , error_status VARCHAR(16777216)
   , error_msg VARCHAR(16777216)
   , creation_ts TIMESTAMP_LTZ DEFAULT sysdate()
   , updation_ts TIMESTAMP_LTZ DEFAULT sysdate()
) ;
CREATE or REPLACE PROCEDURE sp_error_log 
    (proc_name VARCHAR, database_name VARCHAR, 
     schema_name VARCHAR, error_msg VARCHAR, error_stats VARCHAR )
RETURNS STRING
LANGUAGE JAVASCRIPT
AS $$  
    var err_login_flag = true;
    var s_db_name = proc_name;
    var s_db_name = database_name;
    var s_schema_name = schema_name;
    var sl_err_msg = error_msg;
    var s_err_status = error_stats;
    var log_tbl = 't_error_log';
    
    -- Logging error into error log table
    if (err_login_flag ==true){
        var err_login_stmt = `insert into ${s_db_name}.${s_schema_name}.${log_tbl} (sp_name, error_status, error_msg)
            values ('${s_db_name}','${s_err_status}','${sl_err_msg}')`;
        try{
           snowflake.execute({ sqlText: err_login_stmt });
        } catch (ERROR){
            throw ERROR;
            //return err_login_stmt;
        }
    }
$$;
var sp_name = 'MAIN_SP_TEST'; 
        
//Function for logging the error message
Function err_log(err_status,err_msg){
    var err_msg = err_msg;
    try {
        snowflake.createStatement({
            sqlTxt:`Call sp_error_log('${sp_name}','${db_name}','${schema_name}','${err_msg}','${err_stats}')`
        }).execute();
    }catch(err) {
        snowflake.CreateStatement({sqlText:Call sp_error_log('${sp_name}','${db_name}','${schema_name}','Insertion Failed','${err_stats}')`}).execute()
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source