Easily generate json response with error code