Last active
August 29, 2015 14:25
-
-
Save joelalejandro/27c3792d031c1b01cf00 to your computer and use it in GitHub Desktop.
Ember Errorificador
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import errorificador from '../utils/errorificador'; | |
export function initialize(/* container, application */) { | |
var swalError = { swalError: errorificador }; | |
Ember.Controller.reopen(swalError); | |
Ember.Route.reopen(swalError); | |
Ember.Component.reopen(swalError); | |
} | |
export default { | |
name: 'errorificador', | |
initialize: initialize | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function errorificador(error) { | |
var emberAppName = "MiApp"; | |
var appController = window[emberAppName].__container__.lookup('controller:application'); | |
var path = appController.get('currentPath'); | |
var router = window[emberAppName].__container__.lookup('router:main').router; | |
var route = router.getHandler(path); | |
var controller = route.controllerFor(path); | |
var controllerStateKeys = Object.keys(controller.__ember_meta__.values); | |
var controllerState = controllerStateKeys.filter(function(y) { | |
return y != 'controllers'; | |
}).map(function(y) { | |
return { | |
label: y, | |
value: controller.get(y), | |
isNull: controller.get(y) == null | |
}; | |
}).map(function(y) { | |
if (y.isNull) { | |
return { | |
label: y.label, | |
value: null | |
} | |
} | |
if (typeof y.value === 'undefined') { | |
return { | |
label: y.label, | |
value: undefined | |
} | |
} | |
if (y.value.toString().indexOf('model') > -1) { | |
return { | |
label: y.label, | |
value: controller.get(y.label).get('id') | |
}; | |
} | |
if (y.value.get && y.value.type && y.value.type.toString().indexOf('model') > -1) { | |
return { | |
label: y.label, | |
value: y.value.get('content').mapBy('id').join(', ') | |
} | |
} | |
if (y.value && y.value._data) { | |
return { | |
label: y.label, | |
value: y.value._data | |
} | |
} | |
if (typeof y.value === 'boolean' || typeof y.value === 'string' || typeof y.value === 'number') { | |
delete y.isNull; | |
return y; | |
} | |
return { | |
label: y.label, | |
value: '(...)' | |
} | |
}); | |
var controllerStateText = ""; | |
controllerState.forEach(function(state) { | |
controllerStateText += state.label + ": " + JSON.stringify(state.value) + "\r\n"; | |
}) | |
swal({ | |
title: "Se ha producido un error", | |
type: "error", | |
html: "Copie esta información y envíela a Soporte:<br><br>" | |
+ "<textarea rows='10' style='width:660px;font-size:9pt;font-family:monospace'>" | |
+ "Informe de error\r\n" | |
+ "----------------\r\n" | |
+ "Ruta activa: " + path + "\r\n" | |
+ "\r\n" | |
+ "Datos del error\r\n" | |
+ "---------------\r\n" | |
+ JSON.stringify(error.responseJSON, null, " ") + "\r\n" | |
+ "\r\n" | |
+ "Estado del controlador\r\n" | |
+ "----------------------\r\n" | |
+ controllerStateText + "\r\n" | |
+ "\r\n" | |
+ "</textarea>", | |
width: 700 | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Este es un ejemplo de la salida de datos.
Informe de error
Ruta activa: asistencia.calendario.index
Datos del error
{
"Message": "An error has occurred.",
"ExceptionMessage": "ORA-01403: No se ha encontrado ningún dato\nORA-06512: en "procedure", línea 757\nORA-06512: en línea 1",
"ExceptionType": "Oracle.ManagedDataAccess.Client.OracleException",
"StackTrace": " en OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)\r\n en OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean bFirstIterationDone)\r\n en OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int32 lobPrefetchSize, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Boolean isFromEF)\r\n (etc etc etc ... ) "}
Estado del controlador
calendario: "(...)"
tramiteSelected: "812"
centroAtencionSelected: "421"
personaSelected: null
fechaHoraSelected: null
agendaSelected: null
turnoSelected: null
notificacionesAgenda: null
datosAdicionales: null
observaciones: null
procesando: false
semanaPrimero: null
semanaUltimo: null
headingTimeRangeStart: null
headingTimeRangeEnd: null
fraction: null
selectorTramiteAgenda: undefined
tramites: "812"
agendas: null
usuarioEncontrado: "user"
personaEncontrada: "person"
tipoDocumentoSelected: "(...)"
seleccionPersonaConfirmada: true
seguridad: "(...)"
admitirPresencial: true
admitirOrdenLlegada: true
tramiteAgendaSelected: "812"
numeroIdentidad: "12382190"