https://www.codementor.io/@oparaprosper79/understanding-node-error-err_http_headers_sent-117mpk82z8
request with no body -> server should send back 400 to client
request with body -> server should send back 200 to client
The request handler is simply a javascript anonymous function that takes the req& res arguments.
Since this request handler has no explicit command for exiting the function in a situation a request body is not found and the error response is sent back to the client, therefore AFTER THE IF STATEMENT CONDITION has being resolved,
the server tries to send ANOTHER RESPONSE to the client and here is when the error comes up
Express is attempting to set the response header for this second response, hence the error message shows
HOW TO FIX
WHEN SENDING 400 ERR RESPONSE, SEND IT AS RETURN (reponse to a request with no body)
so that the server sends the correct response and STOP the function execution as necessary.
request with no body -> server should send back 400 to client
request with body -> server should send back 200 to client
The request handler is simply a javascript anonymous function that takes the req& res arguments.
Since this request handler has no explicit command for exiting the function in a situation a request body is not found and the error response is sent back to the client, therefore AFTER THE IF STATEMENT CONDITION has being resolved,
the server tries to send ANOTHER RESPONSE to the client and here is when the error comes up
Express is attempting to set the response header for this second response, hence the error message shows
HOW TO FIX
WHEN SENDING 400 ERR RESPONSE, SEND IT AS RETURN (reponse to a request with no body)
so that the server sends the correct response and STOP the function execution as necessary.
댓글
댓글 쓰기