apache / apache/servicecomb-java-chassis
Jackson解析Enum类型出现异常,未使用InvocationException进行捕获处理
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 814
- Avg merge
- 8d 23h
- Merged PRs (30d)
- 1
Description
用户提交的请求参数中Enum值不在swagger的yaml约束的范围内,例如swagger的yaml约束operation为“1”或“2”,输入“operation”:“”或“operation”:“3”,EnumDeserializerl类中使用Jackson解析均会均会抛出JsonMappingException异常,但是RestCodec的restToArgs方法未捕获JsonMappingException,只是使用了Exception来捕获异常但并未获取异常的字段,导致使用spi 机制实现ProduceJsonProcessor时,无法获取框架解析异常的字段,我们需要在RestCodec中捕获json异常,以便于使用ProduceJsonProcessor接收并处理,并向用户展示请求参数中导致异常的字段;建议RestCodec.restToArgs()中使用JsonMappingException.getPath().get(i).getFieldName()接收多个path,并使用throw new InvocationException(Status.BAD_REQUEST, ErrorCode.PARAM_INVALID, stb.toString());把异常抛给ProduceJsonProcessor处理 (或使用InvalidFormatException,但是由于主要是枚举类解析会出现异常,所以也可使用JsonMappingException处理)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading RestCodec.restToArgs and the EnumDeserializerl handling described in the issue. Trace how JsonMappingException paths are currently handled before reaching ProduceJsonProcessor. Done means invalid enum request values produce a BAD_REQUEST InvocationException and expose the relevant field names, including multiple path entries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100