public Response createErrorResponse(RequestOrResponse request, ServerErrorCode serverErrorCode) {
    RequestOrResponseType type = request.getRequestType();
    Response response;
    switch (type) {
      case PutRequest:
        response = new PutResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case GetRequest:
        response = new GetResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case DeleteRequest:
        response = new DeleteResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case TtlUpdateRequest:
        response = new TtlUpdateResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case UndeleteRequest:
        response = new UndeleteResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case ReplicaMetadataRequest:
        response = new ReplicaMetadataResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode,
            ReplicaMetadataResponse.getCompatibleResponseVersion(request.getVersionId()));
        break;
      case AdminRequest:
        response = new AdminResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case ReplicateBlobRequest:
        response = new ReplicateBlobResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case PurgeRequest:
        response = new PurgeResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case FileCopyGetMetaDataRequest:
        response = new FileCopyGetMetaDataResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      case FileCopyGetChunkRequest:
        response = new FileCopyGetMetaDataResponse(request.getCorrelationId(), request.getClientId(), serverErrorCode);
        break;
      default:
        throw new UnsupportedOperationException("Request type not supported");
    }
    return response;
  }
Creates {@link Response} for errors.
@param request incoming request
@param serverErrorCode error code
@return {@link Response} with provided error code
ambry-network/src/main/java/com/github/ambry/network/ServerRequestResponseHelper.java