public NexusClientErrorResponseException( final String reasonPhrase, final String responseBody, final List<ErrorMessage> errorMessages ) { super( message( errorMessages ), Response.Status.BAD_REQUEST.getStatusCode(), reasonPhrase, responseBody ); errors = Collections.unmodifiableList( errorMessages == null ? Collections.<ErrorMessage>emptyList() : errorMessages ); }
public static void dumpErrors(final Task task, final NexusClientErrorResponseException e) { task.log(""); task.log(String.format("Nexus Error Response: %s - %s", e.getResponseCode(), e.getReasonPhrase())); for (NexusClientErrorResponseException.ErrorMessage error : e.errors()) { task.log(String.format(" %s - %s", unfick(error.getId()), unfick(error.getMessage()))); } task.log(""); }
private static String message( final Collection<ErrorMessage> errors ) { if ( errors != null && !errors.isEmpty() ) { final StringBuilder sb = new StringBuilder(); for ( final ErrorMessage error : errors ) { if ( sb.length() > 0 ) { sb.append( "\n" ); } if ( !"*".equals( error.getId() ) ) { sb.append( "[" ).append( error.getId() ).append( "] " ); } sb.append( error.getMessage() ); } if ( errors.size() > 1 ) { sb.insert( 0, "\n" ); } return sb.toString(); } return "Unknown"; }
@Override public String getMetadataPath(final String repositoryId, final MetadataType metadataType) throws IOException { try { final String url = ensureUrlEndsWithSlash(repositoryId); final String location = getLocationOfMetadata(url, metadataType); if (location != null) { return "/" + location; } throw new NexusClientNotFoundException( "Could not find metadata type '" + metadataType.getType() + "'", null ); } catch (UniformInterfaceException e) { throw getNexusClient().convert(e); } catch (ClientHandlerException e) { throw getNexusClient().convert(e); } }
new NexusClientErrorResponseException.ErrorMessage( message.getId(), message.getMsg() ) ); return new NexusClientErrorResponseException( response.getClientResponseStatus().getReasonPhrase(), body,
log.error("Remote staging finished with a failure: {}", e.getMessage()); log.error(""); log.error("Possible causes of 404 Not Found error:"); " * remote Nexus got the profile with ID \"{}\" removed during this build? Get to Nexus admin...", profileId); throw new ArtifactDeploymentException("Remote staging failed: " + e.getMessage(), e); log.error("Remote staging finished with a failure: {}", e.getMessage()); log.error(""); log.error("Possible causes of 403 Forbidden:"); log.error( " * you have no permissions to stage against profile with ID \"{}\"? Get to Nexus admin...", profileId); throw new ArtifactDeploymentException("Remote staging failed: " + e.getMessage(), e);
public NexusClientBadRequestException convertIf400( final UniformInterfaceException e ) { final ClientResponse response = e.getResponse(); if ( ClientResponse.Status.BAD_REQUEST.equals( response.getClientResponseStatus() ) ) { return new NexusClientBadRequestException( getMessageIfPresent( ClientResponse.Status.BAD_REQUEST.getStatusCode(), e ), response.getClientResponseStatus().getReasonPhrase(), getResponseBody( response ) ); } return null; }
public NexusClientAccessForbiddenException convertIf403( final UniformInterfaceException e ) { final ClientResponse response = e.getResponse(); if ( ClientResponse.Status.FORBIDDEN.equals( response.getClientResponseStatus() ) ) { return new NexusClientAccessForbiddenException( getMessageIfPresent( ClientResponse.Status.FORBIDDEN.getStatusCode(), e ), response.getClientResponseStatus().getReasonPhrase(), getResponseBody( response ) ); } return null; }
public NexusClientException convert( final UniformInterfaceException e ) { NexusClientException exception = convertIfKnown( e ); if ( exception != null ) { return exception; } return new NexusClientResponseException( getMessageIfPresent( e.getResponse().getClientResponseStatus().getStatusCode(), e ), e.getResponse().getClientResponseStatus().getStatusCode(), e.getResponse().getClientResponseStatus().getReasonPhrase(), getResponseBody( e.getResponse() ) ); }
public static void dumpErrors(final Writer writer, final NexusClientErrorResponseException e) { writer.writeln(""); writer.writeln(String.format("Nexus Error Response: %s - %s", e.getResponseCode(), e.getReasonPhrase())); for (NexusClientErrorResponseException.ErrorMessage errorEntry : e.errors()) { writer.writeln(String.format(" %s - %s", unfick(errorEntry.getId()), unfick(errorEntry.getMessage()))); } writer.writeln(""); }
@Override public String getMetadataUrl(final String repositoryId, final MetadataType metadataType) throws IOException { try { final String url = ensureUrlEndsWithSlash(repositoryId); final String location = getLocationOfMetadata(url, metadataType); if (location != null) { return url + location; } throw new NexusClientNotFoundException( "Could not find metadata type '" + metadataType.getType() + "'", null ); } catch (UniformInterfaceException e) { throw getNexusClient().convert(e); } catch (ClientHandlerException e) { throw getNexusClient().convert(e); } }
public NexusClientNotFoundException convertIf404( final UniformInterfaceException e ) { final ClientResponse response = e.getResponse(); if ( ClientResponse.Status.NOT_FOUND.equals( response.getClientResponseStatus() ) ) { return new NexusClientNotFoundException( getMessageIfPresent( ClientResponse.Status.NOT_FOUND.getStatusCode(), e ), response.getClientResponseStatus().getReasonPhrase(), getResponseBody( response ) ); } return null; }
@Override public <T> T getMetadata(final String repositoryId, final MetadataType metadataType, final Class<T> returnType) throws IOException { try { final String url = ensureUrlEndsWithSlash(repositoryId); final String location = getLocationOfMetadata(url, metadataType); if (location != null) { return handleResponse( getNexusClient().getClient().resource(url + location).get(ClientResponse.class), returnType, metadataType.getCompression() ); } throw new NexusClientNotFoundException( "Could not find metadata type '" + metadataType.getType() + "'", null ); } catch (UniformInterfaceException e) { throw getNexusClient().convert(e); } catch (ClientHandlerException e) { throw getNexusClient().convert(e); } }
@Override public <T> T getMetadata(final String repositoryId, final String version, final MetadataType metadataType, final Class<T> returnType) throws IOException { try { final String url = getNexusClient().resolveServicePath("yum/repos/" + repositoryId + "/" + version + "/"); final String location = getLocationOfMetadata(url, metadataType); if (location != null) { return handleResponse( getNexusClient().getClient().resource(url + location).get(ClientResponse.class), returnType, metadataType.getCompression() ); } throw new NexusClientNotFoundException( "Could not find metadata type '" + metadataType.getType() + "'", null ); } catch (UniformInterfaceException e) { throw getNexusClient().convert(e); } catch (ClientHandlerException e) { throw getNexusClient().convert(e); } }