+ Start a Discussion
Pat McQueenPat McQueen 

ngforce error handling question

Hello - I am trying to do a multiple child record create with NGForce.  There is a validation rule on the object.  The problem I have is that when the validation rule stops the insert that I can't seem to capture the error and show the end user why the insert failed.  I tried a basic alert(error.message); and it gives me "Error object undefined"  The code works ... As long as the data entry is perfect.  How do I catch a failure and show the error message to the end user?  All I can show now is a generic "The insert has failed with an error"
 
$scope.createAttend = function(student, rowColor){

                var attendRecord = {Scholarship__c : student.Id ,Possible_Days_in_Attendance__c : this.possibleDays , Days_in_Attendance__c : student.totalAttendance, Excused_Absences__c : student.Excused, Check_in_Date__c : this.checkInDate, Notes__c : student.Notes}
              
               vfr.create("Scholarship_Student_Attendance__c",JSON.stringify(attendRecord)).then(
                
                function(response){
                     $filter('filter')($scope.students, {Id : student.Id})[0].wstate = rowColor;                             
                },
                function (error){
                    alert("The insert has failed with an error."); 
                    console.log(error);
                }
            )
           }

 
Best Answer chosen by Pat McQueen
Pat McQueenPat McQueen
Nothing like sleeping on it over night ... Ugh.  It was simple.  Here is the new error function that works great.
 
function (error){
                    console.log(error);
                    var em = 'The record was not saved.';
                    for(var i=0; i<error.length; i++) {
                        em = em + ' ' + error[i].message;
                    }
                    alert(em);