~vladh/radio-api

0c9d4680945dfa4bb185dc23de4fa5c76afcbb7f — Vlad-Stefan Harbuz 1 year, 10 months ago d1b6308 main
improve error handling
1 files changed, 4 insertions(+), 1 deletions(-)

M main.go
M main.go => main.go +4 -1
@@ 5,6 5,7 @@ package main

import (
	"encoding/json"
	"fmt"
	"log"
	"math/rand"
	"net/http"


@@ 177,7 178,9 @@ func handleRandom(w http.ResponseWriter, r *http.Request, ps httprouter.Params) 

	songPaths, err := getSongsInDirs(station.Paths)
	if err != nil {
		resData := ErrResponse{Err: "Could not get songs for station"}
		resData := ErrResponse{
			Err: fmt.Sprintf("Could not get songs for station: %s", err),
		}
		err = json.NewEncoder(w).Encode(resData)
		if err != nil { log.Printf("ERROR: %s\n", err) }
		return