Files
Scriberr/internal/api/log_handler.go
rishikanthc 57232d9c06 fix(api): return graceful empty responses instead of 400/404
- GetTranscript returns 200 with available=false when transcript not ready
- GetJobExecutionData returns 200 with available=false when no execution
- GetJobLogs returns JSON with available=false when no logs exist
- Updated frontend hooks to handle new response format with available field
- Added .gitignore entries for prompt.txt and .agent folder
2025-12-14 19:09:52 -08:00

58 lines
1.4 KiB
Go

package api
import (
"fmt"
"net/http"
"path/filepath"
"github.com/gin-gonic/gin"
)
// GetJobLogs returns the transcription logs for a specific job
// @Summary Get transcription logs
// @Description Get the raw transcription logs for a job
// @Tags transcription
// @Produce text/plain
// @Param id path string true "Job ID"
// @Success 200 {string} string "Log content"
// @Failure 404 {object} ErrorResponse
// @Failure 500 {object} ErrorResponse
// @Router /transcription/{id}/logs [get]
func (h *Handler) GetJobLogs(c *gin.Context) {
jobID := c.Param("id")
// Construct path to log file
logPath := filepath.Join(h.config.TranscriptsDir, jobID, "transcription.log")
// Check if file exists
exists, err := h.fileService.FileExists(logPath)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Failed to check logs: %v", err)})
return
}
if !exists {
// Return graceful empty response instead of 404
c.JSON(http.StatusOK, gin.H{
"job_id": jobID,
"available": false,
"content": "",
"message": "No logs available for this job",
})
return
}
// Read file content
content, err := h.fileService.ReadFile(logPath)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Failed to read logs: %v", err)})
return
}
// Return as JSON with content for consistency
c.JSON(http.StatusOK, gin.H{
"job_id": jobID,
"available": true,
"content": string(content),
})
}