11package com .uid2 .operator .service ;
22
33import com .uid2 .operator .monitoring .TokenResponseStatsCollector ;
4- import com .uid2 .operator .vertx .UIDOperatorVerticle ;
54import com .uid2 .shared .model .TokenVersion ;
65import com .uid2 .shared .store .ISiteStore ;
76import io .vertx .core .http .HttpHeaders ;
@@ -64,19 +63,28 @@ public static void SuccessV2(RoutingContext rc, Object body) {
6463 rc .data ().put ("response" , json );
6564 }
6665
67- public static void ClientError (RoutingContext rc , String message ) {
68- Warning (ResponseStatus .ClientError , 400 , rc , message );
66+ public static void LogInfoAndSend400Response (RoutingContext rc , String message ) {
67+ LogInfoAndSendResponse (ResponseStatus .ClientError , 400 , rc , message );
6968 }
7069
7170 public static void SendClientErrorResponseAndRecordStats (String errorStatus , int statusCode , RoutingContext rc , String message , Integer siteId , TokenResponseStatsCollector .Endpoint endpoint , TokenResponseStatsCollector .ResponseStatus responseStatus , ISiteStore siteProvider , TokenResponseStatsCollector .PlatformType platformType )
7271 {
73- Warning (errorStatus , statusCode , rc , message );
72+ // 400 error
73+ if (ResponseStatus .ClientError .equals (errorStatus ))
74+ {
75+ LogInfoAndSendResponse (errorStatus , statusCode , rc , message );
76+ }
77+ // 4xx error other than 400
78+ else {
79+ LogWarningAndSendResponse (errorStatus , statusCode , rc , message );
80+ }
81+
7482 recordTokenResponseStats (siteId , endpoint , responseStatus , siteProvider , null , platformType );
7583 }
7684
7785 public static void SendServerErrorResponseAndRecordStats (RoutingContext rc , String message , Integer siteId , TokenResponseStatsCollector .Endpoint endpoint , TokenResponseStatsCollector .ResponseStatus responseStatus , ISiteStore siteProvider , Exception exception , TokenResponseStatsCollector .PlatformType platformType )
7886 {
79- Error (ResponseStatus .UnknownError , 500 , rc , message , exception );
87+ LogErrorAndSendResponse (ResponseStatus .UnknownError , 500 , rc , message , exception );
8088 rc .fail (500 );
8189 recordTokenResponseStats (siteId , endpoint , responseStatus , siteProvider , null , platformType );
8290 }
@@ -97,62 +105,40 @@ public static JsonObject Response(String status, String message) {
97105 return json ;
98106 }
99107
100- public static void Error (String errorStatus , int statusCode , RoutingContext rc , String message ) {
101- logError (errorStatus , statusCode , message , new RoutingContextReader (rc ), rc .request ().remoteAddress ().hostAddress ());
108+ public static void LogErrorAndSendResponse (String errorStatus , int statusCode , RoutingContext rc , String message ) {
109+ String msg = ComposeMessage (errorStatus , statusCode , message , new RoutingContextReader (rc ), rc .request ().remoteAddress ().hostAddress ());
110+ LOGGER .error (msg );
102111 final JsonObject json = Response (errorStatus , message );
103112 rc .response ().setStatusCode (statusCode ).putHeader (HttpHeaders .CONTENT_TYPE , "application/json" )
104113 .end (json .encode ());
105114 }
106115
107- public static void Error (String errorStatus , int statusCode , RoutingContext rc , String message , Exception exception ) {
108- logError (errorStatus , statusCode , message , new RoutingContextReader (rc ), rc .request ().remoteAddress ().hostAddress (), exception );
116+ public static void LogErrorAndSendResponse (String errorStatus , int statusCode , RoutingContext rc , String message , Exception exception ) {
117+ String msg = ComposeMessage (errorStatus , statusCode , message , new RoutingContextReader (rc ), rc .request ().remoteAddress ().hostAddress ());
118+ LOGGER .error (msg , exception );
109119 final JsonObject json = Response (errorStatus , message );
110120 rc .response ().setStatusCode (statusCode ).putHeader (HttpHeaders .CONTENT_TYPE , "application/json" )
111121 .end (json .encode ());
112122 }
113123
114- public static void Warning (String status , int statusCode , RoutingContext rc , String message ) {
115- logWarning (status , statusCode , message , new RoutingContextReader (rc ), rc .request ().remoteAddress ().hostAddress ());
124+ public static void LogInfoAndSendResponse (String status , int statusCode , RoutingContext rc , String message ) {
125+ String msg = ComposeMessage (status , statusCode , message , new RoutingContextReader (rc ), rc .request ().remoteAddress ().hostAddress ());
126+ LOGGER .info (msg );
116127 final JsonObject json = Response (status , message );
117128 rc .response ().setStatusCode (statusCode ).putHeader (HttpHeaders .CONTENT_TYPE , "application/json" )
118129 .end (json .encode ());
119130 }
120131
121- private static void logError (String errorStatus , int statusCode , String message , RoutingContextReader contextReader , String clientAddress ) {
122- JsonObject errorJsonObj = JsonObject .of (
123- "errorStatus" , errorStatus ,
124- "contact" , contextReader .getContact (),
125- "siteId" , contextReader .getSiteId (),
126- "statusCode" , statusCode ,
127- "clientAddress" , clientAddress ,
128- "message" , message
129- );
130- final String linkName = contextReader .getLinkName ();
131- if (!linkName .isBlank ()) {
132- errorJsonObj .put (SecureLinkValidatorService .SERVICE_LINK_NAME , linkName );
133- }
134- final String serviceName = contextReader .getServiceName ();
135- if (!serviceName .isBlank ()) {
136- errorJsonObj .put (SecureLinkValidatorService .SERVICE_NAME , serviceName );
137- }
138- LOGGER .error ("Error response to http request. " + errorJsonObj .encode ());
139- }
140-
141- private static void logError (String errorStatus , int statusCode , String message , RoutingContextReader contextReader , String clientAddress , Exception exception ) {
142- String errorMessage = "Error response to http request. " + JsonObject .of (
143- "errorStatus" , errorStatus ,
144- "contact" , contextReader .getContact (),
145- "siteId" , contextReader .getSiteId (),
146- "path" , contextReader .getPath (),
147- "statusCode" , statusCode ,
148- "clientAddress" , clientAddress ,
149- "message" , message
150- ).encode ();
151- LOGGER .error (errorMessage , exception );
132+ public static void LogWarningAndSendResponse (String status , int statusCode , RoutingContext rc , String message ) {
133+ String msg = ComposeMessage (status , statusCode , message , new RoutingContextReader (rc ), rc .request ().remoteAddress ().hostAddress ());
134+ LOGGER .warn (msg );
135+ final JsonObject json = Response (status , message );
136+ rc .response ().setStatusCode (statusCode ).putHeader (HttpHeaders .CONTENT_TYPE , "application/json" )
137+ .end (json .encode ());
152138 }
153139
154- private static void logWarning (String status , int statusCode , String message , RoutingContextReader contextReader , String clientAddress ) {
155- JsonObject warnMessageJsonObject = JsonObject .of (
140+ private static String ComposeMessage (String status , int statusCode , String message , RoutingContextReader contextReader , String clientAddress ) {
141+ JsonObject msgJsonObject = JsonObject .of (
156142 "errorStatus" , status ,
157143 "contact" , contextReader .getContact (),
158144 "siteId" , contextReader .getSiteId (),
@@ -165,14 +151,22 @@ private static void logWarning(String status, int statusCode, String message, Ro
165151 final String origin = contextReader .getOrigin ();
166152 if (statusCode >= 400 && statusCode < 500 ) {
167153 if (referer != null ) {
168- warnMessageJsonObject .put ("referer" , referer );
154+ msgJsonObject .put ("referer" , referer );
169155 }
170156 if (origin != null ) {
171- warnMessageJsonObject .put ("origin" , origin );
157+ msgJsonObject .put ("origin" , origin );
172158 }
173159 }
174- String warnMessage = "Warning response to http request. " + warnMessageJsonObject .encode ();
175- LOGGER .warn (warnMessage );
160+
161+ final String linkName = contextReader .getLinkName ();
162+ if (!linkName .isBlank ()) {
163+ msgJsonObject .put (SecureLinkValidatorService .SERVICE_LINK_NAME , linkName );
164+ }
165+ final String serviceName = contextReader .getServiceName ();
166+ if (!serviceName .isBlank ()) {
167+ msgJsonObject .put (SecureLinkValidatorService .SERVICE_NAME , serviceName );
168+ }
169+ return "Response to http request. " + msgJsonObject .encode ();
176170 }
177171
178172 public static class ResponseStatus {
@@ -183,6 +177,7 @@ public static class ResponseStatus {
183177 public static final String InvalidToken = "invalid_token" ;
184178 public static final String ExpiredToken = "expired_token" ;
185179 public static final String GenericError = "error" ;
180+ public static final String InvalidClient = "invalid_client" ;
186181 public static final String UnknownError = "unknown" ;
187182 public static final String InsufficientUserConsent = "insufficient_user_consent" ;
188183 public static final String InvalidHttpOrigin = "invalid_http_origin" ;
0 commit comments