package handlers import ( "errors" "net/http" "galaxy/gamemaster/internal/domain/runtime" ) // newGetRuntimeHandler returns the handler for // `GET /api/v1/internal/runtimes/{game_id}`. Reads from // `RuntimeRecordsReader.Get` and translates `runtime.ErrNotFound` to // `404 runtime_not_found`. func newGetRuntimeHandler(deps Dependencies) http.HandlerFunc { logger := loggerFor(deps.Logger, "internal_rest.get_runtime") return func(writer http.ResponseWriter, request *http.Request) { if deps.RuntimeRecords == nil { writeError(writer, http.StatusInternalServerError, errorCodeInternal, "runtime records store is not wired") return } gameID, ok := extractGameID(writer, request) if !ok { return } record, err := deps.RuntimeRecords.Get(request.Context(), gameID) if err != nil { if errors.Is(err, runtime.ErrNotFound) { writeError(writer, http.StatusNotFound, errorCodeRuntimeNotFound, "runtime not found") return } logger.ErrorContext(request.Context(), "get runtime record failed", "game_id", gameID, "err", err.Error(), ) writeError(writer, http.StatusInternalServerError, errorCodeInternal, "failed to read runtime record") return } writeJSON(writer, http.StatusOK, encodeRuntimeRecord(record)) } }