Move to regex match for CDS error message 50/1150/1
authorSerban Jora <sj2381@att.com>
Thu, 1 Mar 2018 16:41:00 +0000 (11:41 -0500)
committerSerban Jora <sj2381@att.com>
Thu, 1 Mar 2018 16:41:27 +0000 (11:41 -0500)
Change-Id: Ib26363e3b751f4bbf0ac72fc362c9dd438baebce
Signed-off-by: Serban Jora <sj2381@att.com>
Issue-ID: ACUMOS-276

gateway/src/main/java/org/acumos/federation/gateway/util/Errors.java

index d133e6e..ab3b5fa 100644 (file)
@@ -20,6 +20,9 @@
 
 package org.acumos.federation.gateway.util;
 
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
 import org.springframework.http.HttpStatus;
 import org.springframework.web.client.HttpStatusCodeException;
 
@@ -29,6 +32,17 @@ public class Errors {
        private Errors() {
        }
 
+       private static Pattern cdsNotFoundPattern = null;
+       {
+               try {
+                       cdsNotFoundPattern = Pattern.compile("No (.*) for ID (.*)");
+               }
+               catch (PatternSyntaxException psx) {
+                       throw new RuntimeException("Invalid error pattern", psx);
+               }
+       }
+
+
        /**
         * CDS provides a 400 error with a particular error message
         * 
@@ -41,7 +55,8 @@ public class Errors {
                if (theError.getStatusCode() == HttpStatus.BAD_REQUEST) {
                        String msg = theError.getResponseBodyAsString();
                        if (msg != null) {
-                               return ((String) Utils.jsonStringToMap(msg).getOrDefault("error", "")).startsWith("No entry for ID");
+                               return cdsNotFoundPattern.matcher((String) Utils.jsonStringToMap(msg).getOrDefault("error", ""))
+                                                               .matches();
                        }
                }
                return false;