11package com .phuocnguyen .app .ngxblobso2jwt .utils ;
22
33import com .fasterxml .jackson .databind .ObjectMapper ;
4+ import com .sivaos .Configurer .CustomFilterRequest .TypeSafeRequest ;
5+ import com .sivaos .Model .ObjectEnumeration .Original .ComparatorType ;
46import com .sivaos .Model .Response .Extend .HttpStatusCodesResponseDTO ;
57import com .sivaos .Model .Response .Extend .StatusCodeResponseDTO ;
8+ import com .sivaos .Utility .CollectionsUtility ;
69import com .sivaos .Utils .DateUtils ;
10+ import com .sivaos .Utils .ObjectUtils ;
11+ import com .sivaos .Utils .UrlQueryUtils ;
712import org .slf4j .Logger ;
813import org .slf4j .LoggerFactory ;
914import org .springframework .http .MediaType ;
@@ -37,15 +42,24 @@ public static void onHandlerErrors(HttpServletRequest request, HttpServletRespon
3742
3843 Map <String , Object > map = new HashMap <>();
3944
40- map .put ("code" , statuses .getCode ());
41- map .put ("header" , statuses );
42- map .put ("message" , exception .getMessage ());
43- map .put ("path" , request .getServletPath ());
44- map .put ("timestamp" , new Date ().getTime ());
45- map .put ("publish" , DateUtils .feedStageAsString (new Date ()));
46- map .put ("class" , clazz );
47- map .put ("method" , request .getMethod ());
48- map .put ("sessionId" , request .getSession ().getId ());
45+ Map <String , String > queries = TypeSafeRequest .snapTypeSafeRequest (request );
46+ String urlShortCompleted = UrlQueryUtils .snapQuery (request .getServletPath (), CollectionsUtility .sortByKey (queries , ComparatorType .ASCENDING ));
47+
48+ map .put (HandlerAttributes .CODE_ATTRIBUTE , statuses .getCode ());
49+ map .put (HandlerAttributes .HEADER_ATTRIBUTE , statuses );
50+ map .put (HandlerAttributes .MESSAGE_ATTRIBUTE , exception .getMessage ());
51+ map .put (HandlerAttributes .PATH_ATTRIBUTE , urlShortCompleted );
52+ map .put (HandlerAttributes .TIMESTAMP_ATTRIBUTE , new Date ().getTime () / 1000 );
53+ map .put (HandlerAttributes .PUBLISH_ATTRIBUTE , DateUtils .feedStageAsString (new Date ()));
54+ map .put (HandlerAttributes .CLASS_ATTRIBUTE , clazz );
55+ map .put (HandlerAttributes .METHOD_ATTRIBUTE , request .getMethod ());
56+ map .put (HandlerAttributes .DEBUG_MESSAGE_ATTRIBUTE , exception .getLocalizedMessage ());
57+
58+ if (ObjectUtils .allNotNull (request .getSession ())) {
59+ map .put (HandlerAttributes .SESSION_ID_ATTRIBUTE , request .getSession ().getId ());
60+ } else {
61+ map .put (HandlerAttributes .SESSION_ID_ATTRIBUTE , request .getRequestedSessionId ());
62+ }
4963
5064 try {
5165 ObjectMapper mapper = new ObjectMapper ();
@@ -55,4 +69,17 @@ public static void onHandlerErrors(HttpServletRequest request, HttpServletRespon
5569 throw new ServletException (e .getMessage (), e );
5670 }
5771 }
72+
73+ private static class HandlerAttributes {
74+ public static final String CODE_ATTRIBUTE = "code" ;
75+ public static final String HEADER_ATTRIBUTE = "header" ;
76+ public static final String MESSAGE_ATTRIBUTE = "message" ;
77+ public static final String PATH_ATTRIBUTE = "path" ;
78+ public static final String TIMESTAMP_ATTRIBUTE = "timestamp" ;
79+ public static final String PUBLISH_ATTRIBUTE = "publish" ;
80+ public static final String CLASS_ATTRIBUTE = "class" ;
81+ public static final String METHOD_ATTRIBUTE = "method" ;
82+ public static final String DEBUG_MESSAGE_ATTRIBUTE = "debugMsg" ;
83+ public static final String SESSION_ID_ATTRIBUTE = "sessionId" ;
84+ }
5885}
0 commit comments