...
1 package errors
2
3 import (
4 "net/http"
5
6 "github.com/gin-gonic/gin"
7
8 "edge-infra.dev/pkg/edge/iam/log"
9 )
10
11 type EsodError struct{}
12
13 func NewEsodError(router *gin.Engine) *EsodError {
14 es := &EsodError{}
15 router.GET("/esod-metadata", es.EsodMetadata)
16 return es
17 }
18
19 func (es *EsodError) EsodMetadata(ctx *gin.Context) {
20 log := log.Get(ctx.Request.Context())
21 reason := ctx.Query("reason")
22 log.Info("esod was called", "reason", reason)
23 metadata := NewEsodMetadata()
24
25 switch reason {
26 case "", "unknown":
27
28 case "invalid_session":
29 metadata.
30 WithReason("invalid_session").
31 WithSubtitle("Invalid Session").
32 WithMessage("We couldn't work with your login session. Please close this window and login again to continue.").
33 WithInfo("could not find required information in the session")
34 case "session_expired":
35 metadata.
36 WithReason("session_expired").
37 WithSubtitle("Session Expired").
38 WithMessage("Sorry, your session has probably expired. We can't continue without it. Please close this window and login again to continue.")
39 case "invalid_continuation":
40 metadata.
41 WithReason("invalid_continuation").
42 WithSubtitle("Invalid Session").
43 WithMessage("We couldn't work with your login session. Please close this window and login again to continue.").
44 WithInfo("we couldn't find a valid continuation in your session")
45 case "invalid_request_url":
46 metadata.
47 WithReason("invalid_request_url").
48 WithSubtitle("Invalid Session").
49 WithMessage("We couldn't work with your login session. Please close this window and login again to continue.").
50 WithInfo("we couldn't find a valid request URL in your session")
51 case "invalid_hint":
52 metadata.
53 WithReason("invalid_hint").
54 WithSubtitle("Invalid login hint").
55 WithInfo("we couldn't validate the supplied login hint")
56 case "invalid_client":
57 metadata.
58 WithReason("invalid_client").
59 WithSubtitle("Invalid client id").
60 WithInfo("we did not send the login hint to this client id")
61 case "inactive_hint":
62 metadata.
63 WithReason("inactive_hint").
64 WithSubtitle("Invalid Session").
65 WithMessage("Login hint already used. Please close this window and login again to continue.").
66 WithInfo("the supplied login hint is not active since it was already used")
67 case "offline_with_control_plane":
68 metadata.
69 WithReason("offline_with_control_plane").
70 WithSubtitle("Temporarily offline").
71 WithMessage("The requested feature is not supported while offline. Please close this window and try again later.").
72 WithInfo("some features like printing barcodes are supported only while online")
73 case "invalid_auth_request":
74 metadata.
75 WithReason("invalid_auth_request").
76 WithSubtitle("Invalid login request").
77 WithMessage("Either the clientID or any of the other required params aren't matching with pre-configured details for the client").
78 WithInfo("Invalid authorization request, the request is malformed, or do not match the expected criteria for the given client")
79 case "invalid_auth_response":
80 metadata.
81 WithReason("invalid_auth_response").
82 WithSubtitle("Invalid response type").
83 WithMessage("The response request do not match the pre-configured types for the client").
84 WithInfo("Invalid authorization response, the request does not match the expected criteria for the given client i.e., response mode or response type")
85 default:
86
87 }
88
89 ctx.JSON(http.StatusOK, &metadata)
90 }
91
View as plain text