[REST] inbox/approve: new response code 400 (#2343)

Related to openhab/openhab-webui#1035

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
pull/2353/head
lolodomo 2021-05-17 21:13:40 +02:00 committed by GitHub
parent e3f12c8a45
commit a3d5f3e8dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -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