From 5db3bd8673bcbdc8be4840faad954bb5449fcebc Mon Sep 17 00:00:00 2001 From: valentinogiardino Date: Thu, 21 Nov 2024 19:22:39 -0300 Subject: [PATCH] #30669 add catch for JobValidationException --- .../v1/contentImport/ContentImportResource.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java index b1fe81a0f573..3d1d3c068657 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java @@ -1,7 +1,9 @@ package com.dotcms.rest.api.v1.contentImport; +import com.dotcms.jobs.business.error.JobValidationException; import com.dotcms.rest.ResponseEntityView; import com.dotcms.rest.WebResource; +import com.dotcms.rest.exception.mapper.ExceptionMapperUtil; import com.dotmarketing.exception.DotDataException; import com.fasterxml.jackson.core.JsonProcessingException; import graphql.VisibleForTesting; @@ -12,6 +14,7 @@ import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; @Path("/v1/content") @@ -49,10 +52,10 @@ public ContentImportResource(final WebResource webResource, final ContentImportH * @return Response containing the job ID */ @POST - @Path("/import") + @Path("/_import") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) - public ResponseEntityView importContent( + public Response importContent( @Context final HttpServletRequest request, @Context final HttpServletResponse response, @BeanParam final ContentImportParams params) @@ -64,7 +67,11 @@ public ResponseEntityView importContent( .rejectWhenNoUser(true) .init(); - final String jobId = importHelper.createJob(CMD_PUBLISH, IMPORT_QUEUE_NAME, params, initDataObject.getUser(), request); - return new ResponseEntityView<>(jobId); + try{ + final String jobId = importHelper.createJob(CMD_PUBLISH, IMPORT_QUEUE_NAME, params, initDataObject.getUser(), request); + return Response.ok(new ResponseEntityView<>(jobId)).build(); + }catch (JobValidationException e) { + return ExceptionMapperUtil.createResponse(null, e.getMessage()); + } } } \ No newline at end of file