should this be inside the if block below? otherwise the msg will get logged even if the 500 response was sent.