- commandResponse = new ClientCommandResponse(handler.getStatusCode(),CommandError.insertPazpar2ErrorXml(command.getCommandName(), "Service Proxy error occurred", new String(response,"UTF-8")),"text/xml"); \r
+ String errorXml = "";\r
+ if (handler.getContentType().contains("xml")) {\r
+ errorXml = CommandError.insertErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Service Proxy error: "+handler.getStatusCode(), new String(response,"UTF-8")); \r
+ } else {\r
+ if (handler.getContentType().contains("html")) {\r
+ String htmlStrippedOfTags = (new String(response,"UTF-8")).replaceAll("\\<[^>]*>","");\r
+ if (htmlStrippedOfTags.toLowerCase().contains("domain")) {\r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Error: Expected XML response from Service Proxy, got HTML with word 'domain' in, probably domain not found.", htmlStrippedOfTags); \r
+ } else {\r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Error: Expected XML response from Service Proxy, got HTML", htmlStrippedOfTags); \r
+ }\r
+ } else {\r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Error: Expected XML response from Service Proxy, got: "+handler.getContentType(), new String(response,"UTF-8"));\r
+ }\r
+ commandResponse = new ClientCommandResponse(handler.getStatusCode(),errorXml,handler.getContentType());\r
+ }\r