0

I am used to write Rest API endpoints, wherein we insert error codes like 400 directly in the response.

return new ResponseEntity<>(HttpStatus.BAD_REQUEST);

I have a piece of golang code(part of gRPC API) returning an error, like:

status.Errorf(codes.FailedPrecondition, ...custom error)

How do we map it to status 400?

Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • 1
    Can you elaborate your question? A http's `HttpStatus.BAD_REQUEST` (code `400`) might be `codes.InvalidArgument` (code: `3`), indicating that the request came with invalid data and the user might retry with a proper request. Is that all what you wanted to know? – NotX Jul 13 '23 at 15:22
  • 1
    `Precondition Failed` (code `412`) would be gRPC's `codes.FailedPrecondition` mapped to http, if that's what you've meant. – NotX Jul 13 '23 at 15:30
  • FailedPrecondition is actually getting mapped to code 500 on client side. I guess InvalidArgument is one which would map to 400. – Mandroid Jul 13 '23 at 15:32
  • Well, `500` is just more generic, but can be used as well. Still not sure that was all you questions was about, though. :) – NotX Jul 13 '23 at 15:38

0 Answers0