55 "context"
66 "encoding/json"
77 "errors"
8+ "fmt"
89 "strings"
910 "testing"
1011
@@ -53,6 +54,7 @@ func TestSubmitUserInputLogsStructuredLoginErrorWithoutCredentials(t *testing.T)
5354 "message" : "LINE login attempt failed" ,
5455 "login_flow" : "credentials" ,
5556 "has_certificate" : false ,
57+ "error_summary" : "API error 400" ,
5658 "http_status" : float64 (400 ),
5759 "line_response_code" : float64 (10051 ),
5860 "line_response_message" : "RESPONSE_ERROR" ,
@@ -76,11 +78,28 @@ func TestSubmitUserInputLogsStructuredLoginErrorWithoutCredentials(t *testing.T)
7678}
7779
7880func TestParseLoginErrorDetailsWithoutJSON (t * testing.T ) {
79- details := parseLoginErrorDetails (errors .New ("login failed: request failed: context deadline exceeded" ))
81+ err := errors .New ("login failed: request failed: context deadline exceeded" )
82+ details := parseLoginErrorDetails (err )
8083 if details .HasHTTPStatus || details .HasResponseFields {
8184 t .Fatalf ("unexpected parsed response details: %#v" , details )
8285 }
83- if got := loginErrorSummary (errors .New ("login failed: request failed: context deadline exceeded" )); got != "login failed: request failed: context deadline exceeded" {
84- t .Fatalf ("loginErrorSummary = %q" , got )
86+ if got := loginErrorSummary (err , details ); got != "" {
87+ t .Fatalf ("loginErrorSummary = %q, want empty" , got )
88+ }
89+ }
90+
91+ func TestLoginErrorSummaryDoesNotIncludeNonJSONResponseBody (t * testing.T ) {
92+ err := errors .New ("login failed: API error 502: upstream secret response" )
93+ details := parseLoginErrorDetails (err )
94+ if got := loginErrorSummary (err , details ); got != "API error 502" {
95+ t .Fatalf ("loginErrorSummary = %q, want %q" , got , "API error 502" )
96+ }
97+ }
98+
99+ func TestLoginErrorSummaryAllowsKnownContextErrors (t * testing.T ) {
100+ err := fmt .Errorf ("login failed: %w" , context .DeadlineExceeded )
101+ details := parseLoginErrorDetails (err )
102+ if got := loginErrorSummary (err , details ); got != "request timed out" {
103+ t .Fatalf ("loginErrorSummary = %q, want %q" , got , "request timed out" )
85104 }
86105}
0 commit comments