@ResponseStatus
only allows you to use HttpStatus
as the parameter, and HttpStatus
does not allow you to provide a custom code (it's an enum, so the set of values is fixed).
To return a custom status code, you'll need to change your controller method to return ResponseEntity<YourResponseType>
, and then specify the code via HttpStatusCode.valueOf
:
return new ResponseEntity<String>("Hello World", HttpStatusCode.valueOf(210));
It is worth mentioning that 210 is not a status code that is defined in the HTTP spec - if possible, you'd probably be better off changing to use a status code that more accurately reflects the outcome of the API call. But I appreciate sometimes you have to do weird things when integrating systems :)