Skip to content

Commit 55b1840

Browse files
committed
improved error handling if Factorio server did not start correctly
1 parent 798541e commit 55b1840

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/handlers.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -590,21 +590,26 @@ func StartServer(w http.ResponseWriter, r *http.Request) {
590590
log.Printf("Error starting Factorio server: %s", err)
591591
resp.Data = fmt.Sprintf("Error starting Factorio server: %s", err)
592592
if err := json.NewEncoder(w).Encode(resp); err != nil {
593-
log.Printf("Error encoding start server JSON reponse: ", err)
593+
log.Printf("Error encoding start server JSON response: ", err)
594594
}
595595
return
596596
}
597597
}()
598598

599599
if FactorioServ.Running {
600-
log.Printf("Factorio server started on port: %d", FactorioServ.Port)
601-
}
602-
603-
resp.Data = fmt.Sprintf("Factorio server with save: %s started on port: %d", FactorioServ.Savefile, FactorioServ.Port)
604-
resp.Success = true
605-
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
606-
if err := json.NewEncoder(w).Encode(resp); err != nil {
607-
log.Printf("Error encoding config file JSON reponse: ", err)
600+
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
601+
resp.Data = fmt.Sprintf("Factorio server with save: %s started on port: %d", FactorioServ.Savefile, FactorioServ.Port)
602+
resp.Success = true
603+
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
604+
if err := json.NewEncoder(w).Encode(resp); err != nil {
605+
log.Printf("Error encoding config file JSON reponse: ", err)
606+
}
607+
} else {
608+
log.Printf("Error starting Factorio server: %s", err)
609+
resp.Data = fmt.Sprintf("Error starting Factorio server: %s", err)
610+
if err := json.NewEncoder(w).Encode(resp); err != nil {
611+
log.Printf("Error encoding start server JSON response: ", err)
612+
}
608613
}
609614
}
610615
}

0 commit comments

Comments
 (0)