Reputation: 5240
How can I return HTTP response with status code 202?
I couldn't find any reference for it in Spring Boot documentation.
Upvotes: 2
Views: 11238
Reputation: 604
You can do like this (I am using kotlin) :
return ResponseEntity.accepted().body(OrderResponse().order(order))
OR Easy way is:
return ResponseEntity.status(HttpStatus.CREATED).body(OrderResponse().order(order))
ResponseEntity.accepted returns 202 ResponseEntity.created returns 201 and so on
Upvotes: 2
Reputation: 1
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value=HttpStatus.NOT_FOUND, reason="No Article found with this Article Number.")
public class NoArticleFoundException extends RuntimeException{
private static final long serialVersionUID =3935230281455340039L;
}
Instead of writing NOT_FOUND , you can write ACCEPTED and give some text in reason field. And then call this method from another class or when ever required. (extends part is not required)
Upvotes: -1