package errors import ( "net/http" "github.com/gin-gonic/gin" "edge-infra.dev/pkg/edge/iam/log" ) type EsodError struct{} func NewEsodError(router *gin.Engine) *EsodError { es := &EsodError{} router.GET("/esod-metadata", es.EsodMetadata) return es } func (es *EsodError) EsodMetadata(ctx *gin.Context) { log := log.Get(ctx.Request.Context()) reason := ctx.Query("reason") log.Info("esod was called", "reason", reason) metadata := NewEsodMetadata() switch reason { case "", "unknown": // just use the default metadata... case "invalid_session": metadata. WithReason("invalid_session"). WithSubtitle("Invalid Session"). WithMessage("We couldn't work with your login session. Please close this window and login again to continue."). WithInfo("could not find required information in the session") case "session_expired": metadata. WithReason("session_expired"). WithSubtitle("Session Expired"). WithMessage("Sorry, your session has probably expired. We can't continue without it. Please close this window and login again to continue.") case "invalid_continuation": metadata. WithReason("invalid_continuation"). WithSubtitle("Invalid Session"). WithMessage("We couldn't work with your login session. Please close this window and login again to continue."). WithInfo("we couldn't find a valid continuation in your session") case "invalid_request_url": metadata. WithReason("invalid_request_url"). WithSubtitle("Invalid Session"). WithMessage("We couldn't work with your login session. Please close this window and login again to continue."). WithInfo("we couldn't find a valid request URL in your session") case "invalid_hint": metadata. WithReason("invalid_hint"). WithSubtitle("Invalid login hint"). WithInfo("we couldn't validate the supplied login hint") case "invalid_client": metadata. WithReason("invalid_client"). WithSubtitle("Invalid client id"). WithInfo("we did not send the login hint to this client id") case "inactive_hint": metadata. WithReason("inactive_hint"). WithSubtitle("Invalid Session"). WithMessage("Login hint already used. Please close this window and login again to continue."). WithInfo("the supplied login hint is not active since it was already used") case "offline_with_control_plane": metadata. WithReason("offline_with_control_plane"). WithSubtitle("Temporarily offline"). WithMessage("The requested feature is not supported while offline. Please close this window and try again later."). WithInfo("some features like printing barcodes are supported only while online") case "invalid_auth_request": metadata. WithReason("invalid_auth_request"). WithSubtitle("Invalid login request"). WithMessage("Either the clientID or any of the other required params aren't matching with pre-configured details for the client"). WithInfo("Invalid authorization request, the request is malformed, or do not match the expected criteria for the given client") case "invalid_auth_response": metadata. WithReason("invalid_auth_response"). WithSubtitle("Invalid response type"). WithMessage("The response request do not match the pre-configured types for the client"). WithInfo("Invalid authorization response, the request does not match the expected criteria for the given client i.e., response mode or response type") default: // just use the default metadata... } ctx.JSON(http.StatusOK, &metadata) }