77 "time"
88
99 "github.com/po3rin/github_link_creator/lib/env"
10+ l "github.com/po3rin/github_link_creator/lib/logger"
1011 "github.com/po3rin/github_link_creator/pipeline"
1112
1213 "github.com/gin-gonic/gin"
@@ -24,17 +25,30 @@ func (h *Handler) GetCode(c *gin.Context) {
2425
2526 img , err := pipeline .ProcessingImg (ctx , h .Repo , userName , repoName )
2627 if err != nil {
27- c .JSON (http .StatusInternalServerError , err .Error ())
28+ c .JSON (http .StatusInternalServerError , ErrorResponse {
29+ Message : err .Error (),
30+ DocumentationURL : documentationURL ,
31+ })
32+ l .Error (err )
33+ doneCh <- struct {}{}
2834 return
2935 }
3036 location , err := h .Repo .UploadImg (img , userName + "/" + repoName )
3137 if err != nil {
32- c .JSON (http .StatusInternalServerError , err .Error ())
38+ c .JSON (http .StatusInternalServerError , ErrorResponse {
39+ Message : err .Error (),
40+ DocumentationURL : documentationURL ,
41+ })
42+ l .Error (err )
43+ doneCh <- struct {}{}
3344 return
3445 }
35- result := fmt .Sprintf (`<a href="https://github.com/%v/%v"><img src="%v" width="460px"></a>` , userName , repoName , location )
36- c .JSON (http .StatusOK , gin.H {
37- "value" : result ,
46+ url := fmt .Sprintf ("https://github.com/%v/%v" , userName , repoName )
47+ result := fmt .Sprintf (`<a href="%v"><img src="%v" width="460px"></a>` , url , location )
48+ c .JSON (http .StatusOK , Response {
49+ Value : result ,
50+ RepositoryURL : url ,
51+ CardURL : location ,
3852 })
3953 doneCh <- struct {}{}
4054 }()
@@ -43,8 +57,10 @@ func (h *Handler) GetCode(c *gin.Context) {
4357 case <- doneCh :
4458 return
4559 case <- ctx .Done ():
60+ msg := fmt .Sprintf ("Processing timed out in %d seconds" , env .Timeout )
61+ l .Error (msg )
4662 c .JSON (http .StatusRequestTimeout , gin.H {
47- "message" : fmt . Sprintf ( "Processing timed out in %d seconds" , env . Timeout ) ,
63+ "message" : msg ,
4864 })
4965 }
5066}
0 commit comments