From a3d5f3e8dc41d3f0e4732e78bcdeed09cf1d53dd Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 17 May 2021 21:13:40 +0200 Subject: [PATCH] [REST] inbox/approve: new response code 400 (#2343) Related to openhab/openhab-webui#1035 Signed-off-by: Laurent Garnier --- .../io/rest/core/internal/discovery/InboxResource.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java index 2a5ef201a..39c2b0175 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/discovery/InboxResource.java @@ -104,6 +104,7 @@ public class InboxResource implements RESTResource { @Consumes(MediaType.TEXT_PLAIN) @Operation(operationId = "approveInboxItemById", summary = "Approves the discovery result by adding the thing to the registry.", responses = { @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "400", description = "Invalid new thing ID."), @ApiResponse(responseCode = "404", description = "Thing unable to be approved."), @ApiResponse(responseCode = "409", description = "No binding found that supports this thing.") }) public Response approve( @@ -119,7 +120,11 @@ public class InboxResource implements RESTResource { thing = inbox.approve(thingUIDObject, notEmptyLabel, notEmptyNewThingId); } catch (IllegalArgumentException e) { logger.error("Thing {} unable to be approved: {}", thingUID, e.getLocalizedMessage()); - return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Thing unable to be approved."); + String errMsg = e.getMessage(); + return errMsg != null + && (errMsg.contains("must not contain multiple segments") || errMsg.startsWith("Invalid thing UID")) + ? JSONResponse.createErrorResponse(Status.BAD_REQUEST, "Invalid new thing ID.") + : JSONResponse.createErrorResponse(Status.NOT_FOUND, "Thing unable to be approved."); } // inbox.approve returns null if no handler is found that supports this thing