Skip to content

Commit

Permalink
Add StreamConstraintsException catch and response for npm contents ge…
Browse files Browse the repository at this point in the history
…nerating
  • Loading branch information
yma96 committed Mar 26, 2024
1 parent 3f92b1f commit e8c50a4
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.commonjava.indy.pkg.npm.jaxrs;

import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -121,6 +122,13 @@ public Response doCreate( String packageType, String type, String name, String p
// generate .http-metadata.json for hosted repo to resolve npm header requirements
generateHttpMetadataHeaders( metadataFile, generated, request, response );
}
catch ( final StreamConstraintsException e )
{
logger.error( String.format(
"Failed to upload due to violation of Jackson stream constraint: %s to: %s. Reason: %s", path, name,
e.getMessage() ), e );
response = responseHelper.formatResponse( e, builderModifier );
}
catch ( final IndyWorkflowException | IOException e )
{
logger.error( String.format( "Failed to upload: %s to: %s. Reason: %s", path, name, e.getMessage() ), e );
Expand Down Expand Up @@ -461,6 +469,7 @@ private Object replaceOrigin( String baseUri, String proxyOrigin )
}

private List<Transfer> generateNPMContentsFromTransfer( final Transfer transfer, final EventMetadata eventMetadata )
throws StreamConstraintsException
{
if ( transfer == null || !transfer.exists() )
{
Expand Down Expand Up @@ -526,9 +535,18 @@ private List<Transfer> generateNPMContentsFromTransfer( final Transfer transfer,
tarballTarget = transfers.getCacheReference( new ConcreteResource( resource.getLocation(), tarballPath ) );

}
catch ( final StreamConstraintsException e )
{
// Refer to https://www.javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.15.2/com/fasterxml/jackson/core/exc/StreamConstraintsException.html
logger.error( String.format(
"[NPM] Json node parse failed due to violation of Jackson stream constraint: %s. Reason: %s",
resource, e.getMessage() ), e );
throw e;
}
catch ( final IOException e )
{
logger.error( String.format( "[NPM] Json node parse failed for resource: %s. Reason: %s", resource, e.getMessage() ), e );
logger.error( String.format( "[NPM] Json node parse failed for resource: %s. Reason: %s", resource,
e.getMessage() ), e );
}

if ( versionTarget == null || tarballTarget == null )
Expand Down

0 comments on commit e8c50a4

Please sign in to comment.