{"id":1243,"hash":"321f7dc94696631a8535560cbc4b6c01fadec77ac6ab2b94196ac9c0ac352aaf","pattern":"How to avoid Golang server (Gin Gonic) to crash on INTERNAL_ERROR","full_message":"first of all : I'm new to Go, I come from years of java development.\n\nI have developed a little REST API using Gin Gonic.\nOne of my endpoint occasionally (so I can't reproduce on demand) crashes during an HTTP Get to an external API I don't manage. The error displayed is something like : \n\n  stream error: stream ID 4; INTERNAL_ERROR\n\nAn extract from the code crashing : \n\nclient := &http.Client{}\nreq, err := http.NewRequest(\"GET\", apiUrl, nil)\nif err != nil{\n    log.Fatal(err)\n    return result, err\n}\nresp, err := client.Do(req)\nif err != nil {\n    log.Fatal(err)\n    return result, err\n}\ndefer resp.Body.Close()\n\nThis crashes my server and stops it.\n\nI don't understand what's happening, I'm handling all the errors in the code, so it looks like an uncaught exception comparing to java, but I don't know how to catch that error and keep my server running (I don't care about avoid the error itself, I just want my server to keep going).","ecosystem":"go","package_name":"rest","package_version":null,"solution":"In gin-gonic you can use gin.Recover() middleware that helps your application to recover from panic.\n\nYou can use instantiation via gin.New() or via gin.Default() (it's already included)\n\nhandlers := gin.New()\nhandlers.Use(gin.Recovery())","confidence":0.8500000000000001,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/61674891/how-to-avoid-golang-server-gin-gonic-to-crash-on-internal-error","votes":5,"created_at":"2026-04-19T04:52:41.407389+00:00","updated_at":"2026-04-19T04:52:41.407389+00:00"}