@Test public void testHandleError_noException_withDetails() { Response response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( REST_APP_EXEC_ERROR, name( "toto" )), null ).build(); Assert.assertEquals( Status.FORBIDDEN.getStatusCode(), response.getStatus()); Assert.assertEquals( "{\"reason\":\"" + tb.getString( REST_APP_EXEC_ERROR.toString()) + " Name: toto\"}", response.getEntity()); }
public static ResponseBuilder handleError( int status, RestError restError, String lang ) { List<RoboconfError> errors = new ArrayList<> (); errors.add( restError ); if( restError.getException() instanceof InvalidApplicationException ) { errors.addAll(((InvalidApplicationException) restError.getException()).getErrors()); } StringBuilder sb = new StringBuilder(); String sep = "\n\n"; for( String s : RoboconfErrorHelpers.formatErrors( errors, null, false ).values()) { sb.append( s ); sb.append( sep ); sep = "\n"; } String msg = sb.toString().trim() .replaceAll( "\"", "\\\"" ) .replaceAll( "\n", "\\\\n" ) .replaceAll( "\r", "\\\\r" ) .replaceAll( "\t", "\\\\t" ); return Response.status( status ).entity( "{\"reason\":\"" + msg + "\"}" ); }
RestServicesUtils { public static ResponseBuilder handleError( int status, RestError restError, String lang ) { List<RoboconfError> errors = new ArrayList<> (); errors.add( restError ); if( restError.getException() instanceof InvalidApplicationException ) { errors.addAll(((InvalidApplicationException) restError.getException()).getErrors()); } StringBuilder sb = new StringBuilder(); String sep = "\n\n"; for( String s : RoboconfErrorHelpers.formatErrors( errors, null, false ).values()) { sb.append( s ); sb.append( sep ); sep = "\n"; } String msg = sb.toString().trim() .replaceAll( "\"", "\\\"" ) .replaceAll( "\n", "\\\\n" ) .replaceAll( "\r", "\\\\r" ) .replaceAll( "\t", "\\\\t" ); return Response.status( status ).entity( "{\"reason\":\"" + msg + "\"}" ); } }
RestServicesUtils { public static ResponseBuilder handleError( int status, RestError restError, String lang ) { List<RoboconfError> errors = new ArrayList<> (); errors.add( restError ); if( restError.getException() instanceof InvalidApplicationException ) { errors.addAll(((InvalidApplicationException) restError.getException()).getErrors()); } StringBuilder sb = new StringBuilder(); String sep = "\n\n"; for( String s : RoboconfErrorHelpers.formatErrors( errors, null, false ).values()) { sb.append( s ); sb.append( sep ); sep = "\n"; } String msg = sb.toString().trim() .replaceAll( "\"", "\\\"" ) .replaceAll( "\n", "\\\\n" ) .replaceAll( "\r", "\\\\r" ) .replaceAll( "\t", "\\\\t" ); return Response.status( status ).entity( "{\"reason\":\"" + msg + "\"}" ); } private  RestServicesUtils(); }
RestServicesUtils { public static ResponseBuilder handleError( int status, RestError restError, String lang ) { List<RoboconfError> errors = new ArrayList<> (); errors.add( restError ); if( restError.getException() instanceof InvalidApplicationException ) { errors.addAll(((InvalidApplicationException) restError.getException()).getErrors()); } StringBuilder sb = new StringBuilder(); String sep = "\n\n"; for( String s : RoboconfErrorHelpers.formatErrors( errors, null, false ).values()) { sb.append( s ); sb.append( sep ); sep = "\n"; } String msg = sb.toString().trim() .replaceAll( "\"", "\\\"" ) .replaceAll( "\n", "\\\\n" ) .replaceAll( "\r", "\\\\r" ) .replaceAll( "\t", "\\\\t" ); return Response.status( status ).entity( "{\"reason\":\"" + msg + "\"}" ); } private  RestServicesUtils(); static ResponseBuilder handleError( int status, RestError restError, String lang ); static ResponseBuilder handleError( Status status, RestError restError, String lang ); static String lang( Manager manager ); }
RestServicesUtils { public static ResponseBuilder handleError( int status, RestError restError, String lang ) { List<RoboconfError> errors = new ArrayList<> (); errors.add( restError ); if( restError.getException() instanceof InvalidApplicationException ) { errors.addAll(((InvalidApplicationException) restError.getException()).getErrors()); } StringBuilder sb = new StringBuilder(); String sep = "\n\n"; for( String s : RoboconfErrorHelpers.formatErrors( errors, null, false ).values()) { sb.append( s ); sb.append( sep ); sep = "\n"; } String msg = sb.toString().trim() .replaceAll( "\"", "\\\"" ) .replaceAll( "\n", "\\\\n" ) .replaceAll( "\r", "\\\\r" ) .replaceAll( "\t", "\\\\t" ); return Response.status( status ).entity( "{\"reason\":\"" + msg + "\"}" ); } private  RestServicesUtils(); static ResponseBuilder handleError( int status, RestError restError, String lang ); static ResponseBuilder handleError( Status status, RestError restError, String lang ); static String lang( Manager manager );  }