public void function onError(required any exception,required string eventName){
local['s_event']={
'onApplicationStart'='as'
, 'onRequestStart'='rs'
, 'onRESTRequest'='rr'
, 'onPageLoading'='pl'
, 'onRequestEnd'='re'
, 'onAbort'='ab'
, 'onApplicationEnd'='ae'
, 'onError'='er'
};
arguments['eventName']=((yesNoFormat(len(trim(arguments['eventName']))))?(arguments['eventName']):('onPageLoading'));
local['s_timeZone']={
'v_UTC'=duplicate(getTimeZoneInfo()['utcTotalOffset'])
, 'v_local'=duplicate(getTimeZoneInfo()['utcTotalOffset'])*(-1)
};
local['v_folder']=expandPath('/')&'debug\'&'_'&dateFormat(dateAdd('s',local['s_timeZone']['v_UTC'],now()),'yyyy-mm-dd');
if(not(directoryExists(local['v_folder']))){
directoryCreate(local['v_folder']);
}
local['q_listErrorFiles']=directoryList(path=local['v_folder'],listInfo='query');
local['v_file']=timeFormat(dateAdd('s',local['s_timeZone']['v_UTC'],now()),'HH-mm-ss-lll');
local['v_simultaneous']=0;
local['s_query']={
'v_sql'="
select
1
from [local].[q_listErrorFiles]
where name=:v_errorFileName
;"
, 's_params'={
'v_errorFileName'={
'cfsqltype'='cf_sql_varchar'
, 'value'='_'&local['v_file']&toString(numberFormat(local['v_simultaneous'],'000'))&'_'&local['s_event'][arguments['eventName']]&'.html'
}
}
};
local['q_getErrorFile']=queryExecute(sql=local['s_query']['v_sql'],params=local['s_query']['s_params'],options={'DBType'='query'});
while(local['q_getErrorFile'].recordCount>0){
local['v_simultaneous']=local['v_simultaneous']+1;
local['s_query']={
'v_sql'="
select
1
from [local].[q_listErrorFiles]
where name=:v_errorFileName
;"
, 's_params'={
'v_errorFileName'={
'cfsqltype'='cf_sql_varchar'
, 'value'='_'&local['v_file']&toString(numberFormat(local['v_simultaneous'],'000'))&'_'&local['s_event'][arguments['eventName']]&'.html'
}
}
};
local['q_getErrorFile']=queryExecute(sql=local['s_query']['v_sql'],params=local['s_query']['s_params'],options={'DBType'='query'});
}
local['v_file']=local['v_folder']&'\'&'_'&local['v_file']&toString(numberFormat(local['v_simultaneous'],'000'))&'_'&local['s_event'][arguments['eventName']]&'.html';
fileWrite(local['v_file'],'','utf-8');
writeDump(var=getHTTPRequestData(),label='getHTTPRequestData()',format='html',output=local['v_file']);
writeDump(var=arguments,label='arguments',format='html',output=local['v_file']);
if(isDefined('variables')){
writeDump(var=variables,label='variables',format='html',output=local['v_file']);
}
writeDump(var=cgi,label='cgi',format='html',output=local['v_file']);
writeDump(var=server,label='server',format='html',output=local['v_file']);
if(isDefined('application')){
writeDump(var=application,label='application',format='html',output=local['v_file']);
}
writeDump(var=cookie,label='cookie',format='html',output=local['v_file']);
writeDump(var=url,label='url',format='html',output=local['v_file']);
if(isDefined('form')){
writeDump(var=form,label='form',format='html',output=local['v_file']);
}
return;
}
public void function onError(required any exception,required string eventName){
local['s_event']={
'onApplicationStart'='as'
, 'onRequestStart'='rs'
, 'onRESTRequest'='rr'
, 'onPageLoading'='pl'
, 'onRequestEnd'='re'
, 'onAbort'='ab'
, 'onApplicationEnd'='ae'
, 'onError'='er'
};
arguments['eventName']=((yesNoFormat(len(trim(arguments['eventName']))))?(arguments['eventName']):('onPageLoading'));
local['v_folder']=expandPath('/')&'debug\'&'_'&dateFormat(now(),'yyyy-mm-dd');
if(not(directoryExists(local['v_folder']))){
directoryCreate(local['v_folder']);
}
local['q_listErrorFiles']=directoryList(path=local['v_folder'],listInfo='query');
local['v_file']=timeFormat(now(),'HH-mm-ss-lll');
local['v_simultaneous']=0;
local['s_query']={
'v_sql'="
select
1
from [local].[q_listErrorFiles]
where name=:v_errorFileName
;"
, 's_params'={
'v_errorFileName'={
'cfsqltype'='cf_sql_varchar'
, 'value'='_'&local['v_file']&toString(numberFormat(local['v_simultaneous'],'000'))&'_'&local['s_event'][arguments['eventName']]&'.html'
}
}
};
local['q_getErrorFile']=queryExecute(sql=local['s_query']['v_sql'],params=local['s_query']['s_params'],options={'DBType'='query'});
while(local['q_getErrorFile'].recordCount>0){
local['v_simultaneous']=local['v_simultaneous']+1;
local['s_query']={
'v_sql'="
select
1
from [local].[q_listErrorFiles]
where name=:v_errorFileName
;"
, 's_params'={
'v_errorFileName'={
'cfsqltype'='cf_sql_varchar'
, 'value'='_'&local['v_file']&toString(numberFormat(local['v_simultaneous'],'000'))&'_'&local['s_event'][arguments['eventName']]&'.html'
}
}
};
local['q_getErrorFile']=queryExecute(sql=local['s_query']['v_sql'],params=local['s_query']['s_params'],options={'DBType'='query'});
}
local['v_file']=local['v_folder']&'\'&'_'&local['v_file']&toString(numberFormat(local['v_simultaneous'],'000'))&'_'&local['s_event'][arguments['eventName']]&'.html';
fileWrite(local['v_file'],'','utf-8');
writeDump(var=getHTTPRequestData(),label='getHTTPRequestData()',format='html',output=local['v_file']);
writeDump(var=arguments,label='arguments',format='html',output=local['v_file']);
if(isDefined('variables')){
writeDump(var=variables,label='variables',format='html',output=local['v_file']);
}
writeDump(var=cgi,label='cgi',format='html',output=local['v_file']);
writeDump(var=server,label='server',format='html',output=local['v_file']);
if(isDefined('application')){
writeDump(var=application,label='application',format='html',output=local['v_file']);
}
writeDump(var=cookie,label='cookie',format='html',output=local['v_file']);
writeDump(var=url,label='url',format='html',output=local['v_file']);
if(isDefined('form')){
writeDump(var=form,label='form',format='html',output=local['v_file']);
}
return;
}
Juntando um com o outro, você pode incluir a linha de debug no evento onRESTRequest:
public any function onRESTRequest(required string cfcname,required string method,required struct args){
local['s_return']=null;
cfinvoke(component=arguments.cfcname,method=arguments.method,argumentCollection=arguments.args,returnVariable='local.s_return');
onError(exception=duplicate(local),eventName='onRESTRequest');
return local['s_return'];
}