@@ -2,6 +2,7 @@ package curl
22
33import (
44 "bytes"
5+ "encoding/json"
56 "fmt"
67 "io"
78 "net/http"
@@ -170,11 +171,29 @@ func getBearerToken(p *print.Printer) (string, error) {
170171 p .Debug (print .ErrorLevel , "configure authentication: %v" , err )
171172 return "" , & errors.AuthError {}
172173 }
173- token , err := auth .GetAuthField (auth .ACCESS_TOKEN )
174+
175+ userSessionExpired , err := auth .UserSessionExpired ()
176+ if err != nil {
177+ return "" , err
178+ }
179+ if userSessionExpired {
180+ return "" , & errors.SessionExpiredError {}
181+ }
182+
183+ accessToken , err := auth .GetAccessToken ()
174184 if err != nil {
175- return "" , fmt .Errorf ("get access token: %w" , err )
185+ return "" , err
186+ }
187+
188+ accessTokenExpired , err := auth .TokenExpired (accessToken )
189+ if err != nil {
190+ return "" , err
191+ }
192+ if accessTokenExpired {
193+ return "" , & errors.AccessTokenExpiredError {}
176194 }
177- return token , nil
195+
196+ return accessToken , nil
178197}
179198
180199func buildRequest (model * inputModel , bearerToken string ) (* http.Request , error ) {
@@ -213,6 +232,22 @@ func outputResponse(p *print.Printer, model *inputModel, resp *http.Response) er
213232 if err != nil {
214233 return fmt .Errorf ("read response body: %w" , err )
215234 }
235+
236+ if strings .Contains (strings .ToLower (string (respBody )), "jwt is expired" ) {
237+ return & errors.SessionExpiredError {}
238+ }
239+
240+ if strings .Contains (strings .ToLower (string (respBody )), "jwt is missing" ) {
241+ return & errors.AuthError {}
242+ }
243+
244+ var prettyJSON bytes.Buffer
245+ if json .Valid (respBody ) {
246+ if err := json .Indent (& prettyJSON , respBody , "" , " " ); err == nil {
247+ respBody = prettyJSON .Bytes ()
248+ } // if indenting fails, fall back to original body
249+ }
250+
216251 output = append (output , respBody ... )
217252
218253 if model .OutputFile == nil {
0 commit comments