Details
-
Bug
-
Resolution: Fixed
-
Medium
-
None
-
Major
-
Description
Issue Summary
Content Label API returns 500 status code (Server Error) instead of 4xx if we pass invalid label names i.e. label name containing invalid characters (':', ';', ',', '.', ' ', '?', '&', '[', ']', '(', ')', '#', '^', '*', '@', '!', '<', '>') or label name size is too long or if we pass more than 20 labels at a time or if user doesn't have EDIT permission to confluence page.
Another problem with the API is its response error messages, some of the error messages contain the label name in args param which had an issue, but some do not. For example, if we pass 2 labels in the payload (which this API allows), one with invalid characters and another with a label name too long (more than 255 characters), then the response is something like below:
Payload:
[ { "prefix": "global", "name": "test-*" }, { "prefix": "global", "name": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest" } ]
Response:
{ "statusCode": 500, "message": "com.atlassian.confluence.core.service.NotValidException: [ValidationError [messageKey=label.contains.invalid.chars, args=[global:test-*, , !, #, &, (, ), *, ,, ., :, ;, <, >, ?, @, [, ], ^]], ValidationError [messageKey=label.name.is.too.long, args=[255]]]" }
It would be great if this can be made consistent by adding the label names to the error message in a consumable format.
Steps to Reproduce
- Call Content Label API (/wiki/rest/api/content/{id}/label) with a payload
[ { "prefix": "global", "name": "test-*" }, { "prefix": "global", "name": "test" } ]
2. Remove edit permission of user from confluence page and call Content Label API (/wiki/rest/api/content/{id}/label) with a payload
[ { "prefix":"global", "name":"test-1" }, { "prefix":"global", "name":"test" } ]
Expected Results
Response status code must be 4xx with a proper error message.
Actual Results
The below responses are thrown for different requests
{ "statusCode": 500, "message": "com.atlassian.confluence.core.service.NotValidException: [ValidationError [messageKey=label.contains.invalid.chars, args=[global:test-*, , !, #, &, (, ), *, ,, ., :, ;, <, >, ?, @, [, ], ^]]]" }
{ "statusCode": 500, "message": "com.atlassian.confluence.core.service.NotValidException: [ValidationError [messageKey=only.personal.labels.permitted, args=[]], ValidationError [messageKey=only.personal.labels.permitted, args=[]]]" }
Workaround
Currently, there is no known workaround for this behavior. A workaround will be added here when available