feat(ai): add provider connection test (#38)
This commit is contained in:
@ -551,3 +551,22 @@ func (h *Handler) CreateAdminUser(c *gin.Context) {
|
||||
}
|
||||
httputil.Created(c, user)
|
||||
}
|
||||
|
||||
// TestAIProvider returns only bounded outcomes from saved configuration.
|
||||
func (h *Handler) TestAIProvider(c *gin.Context) {
|
||||
err := h.connectionTester.Test(c.Request.Context(), c.Param("id"))
|
||||
switch {
|
||||
case err == nil:
|
||||
c.JSON(200, gin.H{"status": "success"})
|
||||
case errors.Is(err, ai.ErrConnectionAuth):
|
||||
c.JSON(200, gin.H{"status": "auth_rejected"})
|
||||
case errors.Is(err, ai.ErrConnectionUnavailable):
|
||||
c.JSON(200, gin.H{"status": "unavailable"})
|
||||
case errors.Is(err, ai.ErrConnectionUnsupported):
|
||||
c.JSON(200, gin.H{"status": "auth_check_unsupported"})
|
||||
case errors.Is(err, ai.ErrConnectionNotFound):
|
||||
c.JSON(404, gin.H{"error": "not found"})
|
||||
default:
|
||||
c.JSON(500, gin.H{"error": "internal server error"})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user