Skip to content

Commit

Permalink
PLATFORM-9079 Switch response format in Pandora webhooks for Kratos
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaste committed Mar 20, 2024
1 parent 3cc1d49 commit e11a5ab
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions selfservice/hook/web_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,6 @@ type (
Messages []errorMessage `json:"messages"`
}

// fandom-start - letter case workaround
detailedMessageFallback struct {
ID int
Text string
Type string
Context json.RawMessage
}

errorMessageFallback struct {
InstancePtr string
Message string
DetailedMessages []detailedMessageFallback
}

rawHookResponseFallback struct {
Messages []errorMessageFallback
}
// fandom-end - letter case workaround

httpConfig struct {
sum string
retries int
Expand Down Expand Up @@ -645,21 +626,12 @@ func (e *WebHook) parseWebhookResponse(resp *http.Response, id *identity.Identit
return nil
} else if resp.StatusCode >= http.StatusBadRequest {
var hookResponse rawHookResponse
var hookResponseFallback rawHookResponseFallback
if err = json.Unmarshal(body, &hookResponse); err != nil {
return errors.Wrap(err, "webhook response could not be unmarshalled properly from JSON")
}

// try to read another format is we could not read detailed messages
if len(hookResponse.Messages) != 0 && len(hookResponse.Messages[0].DetailedMessages) == 0 {
if err = json.Unmarshal(body, &hookResponseFallback); err != nil {
return errors.Wrap(err, "webhook response could not be unmarshalled properly from JSON")
}
}

var validationErrs []*schema.ValidationError

// fandom-start - letter case workaround
if len(hookResponse.Messages) != 0 && len(hookResponse.Messages[0].DetailedMessages) != 0 {
for _, msg := range hookResponse.Messages {
messages := text.Messages{}
Expand All @@ -679,27 +651,7 @@ func (e *WebHook) parseWebhookResponse(resp *http.Response, id *identity.Identit
}
validationErrs = append(validationErrs, schema.NewHookValidationError(msg.InstancePtr, "a webhook target returned an error", messages))
}
} else {
for _, msg := range hookResponseFallback.Messages {
messages := text.Messages{}
for _, detail := range msg.DetailedMessages {
var msgType text.UITextType
if detail.Type == "error" {
msgType = text.Error
} else {
msgType = text.Info
}
messages.Add(&text.Message{
ID: text.ID(detail.ID),
Text: detail.Text,
Type: msgType,
Context: detail.Context,
})
}
validationErrs = append(validationErrs, schema.NewHookValidationError(msg.InstancePtr, "a webhook target returned an error", messages))
}
}
// fandom-end

// fandom-start
validationErr := schema.NewValidationListError(validationErrs)
Expand Down

0 comments on commit e11a5ab

Please sign in to comment.