ErrorTrace Interface
Usage of ErrorTrace Module:
When we use third-party or External server, the chances of Server-side exceptions increase. most of the time client POST/GET request get failed at server-side without showing any notification due to different type of Exception errors.
This module ERRORTRACE store the log of all exceptions in database and display following to user:
- Exception type(i.e File.io.Exception).
- Document Type(i.e docx, pdf ...) which was attached to requested form.
- date and time of Error occurrence.
- Record id is extracted from the form submission request URL.
- URL of the client request which cause exception error(s).
- Status of the error which will be unsolved by default but user can mark the status to solved, failed, closed, acknowledge.
so that he or she can take action accordingly.
User Interface:
Following are the screenshot and explanation of User interface:
Each Exception will display in row with checkbox, Error Type, Document Type, Record Id, Date Occurred, Status and Actions("View StackTrace" button). User can filter the error according to status(All, solved, unsolved) by clicking the of one of the option at the left side. User can search the error by Error Type, Document Type, Record Id, Date Occurred, Status by using the search option at top right.
By clicking the "view stackTrace" button, the details of the row error will display as below:
Code flow:
- First time the client with hit on http://localhost:8181/opensrp-web/errorhandler/index which will hit on following method code in the jsp file with status(for the first time status will be all_error by default):
function getErrors(status){ if(table!=null){ table.destroy(); } // start of all error method for data table. rows_selected = []; table =$('#errorTable').DataTable({ "ajax" : { "url" : content+"/errorhandler/errortrace?status="+status, "dataSrc" : "" }, "columns" : [ { "data" : "check" }, { "data" : "errorType" }, { "data" : "documentType" }, { "data" : "recordId", "defaultContent": "" }, { "data" : "dateOccurred", "type": "date" }, { "data" : "status" }, { "data": "_id" } ], "aoColumnDefs": [ { "mRender": function (data, type, full, meta){ return '<center><input type="checkbox"></center>'; }, "aTargets":[0] }, { "mRender":function ( data, type, full ) { var d = new Date(data); var curr_date = d.getDate(); var curr_month = d.getMonth() + 1; //Months are zero based var curr_year = d.getFullYear(); //console.log(curr_date + "-" + curr_month + "-" + curr_year); return curr_date + "-" + curr_month + "-" + curr_year; }, "aTargets": [4] },{ "mRender": function ( data, type, full ) { // return '<a data-toggle="modal" class="btn btn-info" href="/errorhandler/viewerror?id='+data+'" data-target="#myModal">Click me !</a>'; return "<button type='button' class='btn btn-primary' onclick='viewError(""+data+"") ;' >View StackTrace</button>"; }, "aTargets": [6] }, {"mRender": function ( data, type, full ) { return "<center>"+data+"</center>" },"aTargets": [3] }, {"mRender": function ( data, type, full ) { return "<center>"+data+"</center>" } } ] }); }
User can also filter errors by status by selecting the option at the left side.Each time the view will fit to controller to get error results.
- In Controller, Instead of writing different functions for each different type of the status, there is only one function which will hit regardless to status type.
@RequestMapping(method = GET, value = "/errortrace") @ResponseBody public ResponseEntity<List<ErrorTrace>> allErrors(@RequestParam("status") String status) { List<ErrorTrace> list=null; try { Map<String, Object> model = new HashMap<String, Object>(); if(StringUtils.isBlank(status)) { list = errorTraceService.getAllError(); } else { list = errorTraceService.getErrorsByStatus(status); } model.put("errors", list); return new ResponseEntity<>(list, HttpStatus.OK); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity<>(INTERNAL_SERVER_ERROR); } }
The controller with access CouchDB to get filtered datatable.
@View(name = "all_errors_by_status", map = "function(doc) { if (doc.type === 'ErrorTrace') { emit(doc.status); \} \}") public List<ErrorTrace> findErrorsByStatus(String status) throws DocumentNotFoundException { return db.queryView(createQuery("all_errors_by_status"). key(status).includeDocs(true), ErrorTrace.class); }
we can marked the error as closed, solved, acknowledge,failed by checked number of the rows and update the status at once by selecting the option from dropdown at the header of table.
Code for this:update the status$( "#all_status" ).change(function(e){ var data = table.column( 6 ).data().toArray(); var selectedStatus=$("thead").find('#all_status :selected'); console.log(selectedStatus.val()); i=-1; $.each(data,function(){ i=i+1; var searchIDs = $("#errorTable input:checkbox:checked").map(function(){ return $(this).val(); }).get(); console.log("before if i: "+ searchIDs[i+1]); if(searchIDs[i+1]=="on") { console.log("i: "+ data[i]); if(!(selectedStatus.text()=="")) $.get( content+"/errorhandler/update_status?id="+data[i]+"&status="+selectedStatus.val(), function( data , status) { }); } }); //console.log(data); // Prevent click event from propagating to parent e.stopPropagation(); setInterval(2000); window.location.reload(); });
This site is no longer maintained. Please visit docs.opensrp.io for current documentation.