I am using Redmine Rest API to create project, but I get this error message:
1 2 3 4 5 6 | org.springframework.web.client.HttpClientErrorException: 422 Unprocessable Entity at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:667) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:620) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:580) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at com.cht.commons.web.client.RestRequest.post(RestRequest.java:175) ~[cht-commons-web-client-0.3.0-SNAPSHOT.jar:0.3.0-SNAPSHOT] |
How-To
This error results from the project identifier's limitation.
I provide an illegal project identifier, so I fail to create project.
Owing to the Redmine Rest API cannot provide meaningful information for user, so I need to utilize regular expression to provide meaningful information when the project identifier is not legal.
1 2 3 4 5 6 | private void checkProjectIdentifier(String identifier) { Pattern pattern = Pattern.compile("^[a-z0-9_=]*$"); if (!pattern.matcher(identifier).matches()) { throw new RuntimeException("僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線"); } } |
Reference
[1] https://www.redmine.org/projects/redmine/wiki/Rest_Projects
No comments:
Post a Comment