You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: profile_update.go
    path of file: ./repos/portainer/api/http/handler/hostmanagement/fdo
    
    the code of the file until where you have to start completion: package fdo

import (
	"errors"
	"fmt"
	"net/http"
	"strconv"

	portainer "github.com/portainer/portaine
    
func (handler *Handler) updateProfile(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
	id, err := request.RetrieveNumericRouteVariableValue(r, "id")
	if err != nil {
		return httperror.BadRequest("Bad request", errors.New("missing 'id' query parameter"))
	}

	var payload createProfileFromFileContentPayload
	err = request.DecodeAndValidateJSONPayload(r, &payload)
	if err != nil {
		return httperror.BadRequest("Invalid request payload", err)
	}

	profile, err := handler.DataStore.FDOProfile().Read(portainer.FDOProfileID(id))
	if handler.DataStore.IsErrObjectNotFound(err) {
		return httperror.NotFound("Unable to find a FDO Profile with the specified identifier inside the database", err)
	} else if err != nil {
		return httperror.InternalServerError("Unable to find a FDO Profile with the specified identifier inside the database", err)
	}

	isUnique, err := handler.checkUniqueProfileName(payload.Name, id)
	if err != nil {
		return httperror.InternalServerError(err.Error(), err)
	}
	if !isUnique {
		return httperror.Conflict(fmt.Sprintf("A profile with the name '%s' already exists", payload.Name), errors.New("a profile already exists with this name"))
	}

	filePath, err := handler.FileService.StoreFDOProfileFileFromBytes(strconv.Itoa(int(profile.ID)), []byte(payload.ProfileFileContent))
	if err != nil {
		return httperror.InternalServerError("Unable to update profile", err)
	}
	profile.FilePath = filePath
	profile.Name = payload.Name

	err = handler.DataStore.FDOProfile().Update(profile.ID, profile)
	if err != nil {
		return httperror.InternalServerError("Unable to update profile", err)
	}

	return response.JSON(w, profile)
}