Skip to content

Commit ec8b8ea

Browse files
committed
Use the configured jotform API base url
1 parent 61a0934 commit ec8b8ea

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

oura/jotform/submission.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
)
77

88
type SubmissionResponse struct {
9-
Content Content `json:"content"`
9+
ResponseCode int `json:"responseCode"`
10+
Content Content `json:"content"`
1011
}
1112

1213
type Content struct {
@@ -96,7 +97,7 @@ func (a *Answers) UnmarshalJSON(data []byte) error {
9697
}
9798
answer = cf
9899
default:
99-
return fmt.Errorf("unknown answer type: %s for key %s", typeInfo.Type, key)
100+
continue
100101
}
101102

102103
(*a)[answer.Name()] = answer

oura/jotform/webhook.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
)
1717

1818
const (
19-
BaseURL = "https://api.jotform.com"
20-
2119
EligibleField = "eligible"
2220
NameField = "name"
2321
DateOfBirthField = "dateOfBirth"
@@ -164,7 +162,7 @@ func (w *WebhookProcessor) ensureConsentRecordExists(ctx context.Context, userID
164162
}
165163

166164
func (w *WebhookProcessor) getSubmission(ctx context.Context, submissionID string) (*SubmissionResponse, error) {
167-
url := fmt.Sprintf("%s/v1/submissions/%s", BaseURL, submissionID)
165+
url := fmt.Sprintf("%s/v1/submissions/%s", w.baseURL, submissionID)
168166

169167
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
170168
if err != nil {
@@ -190,5 +188,10 @@ func (w *WebhookProcessor) getSubmission(ctx context.Context, submissionID strin
190188
return nil, errors.Wrap(err, "failed to decode response")
191189
}
192190

191+
// Sometimes the jotform webhook returns a 200 http response with a non-200 response code in the body
192+
if response.ResponseCode != http.StatusOK {
193+
return nil, errors.Newf("unexpected response code: %d", response.ResponseCode)
194+
}
195+
193196
return &response, nil
194197
}

0 commit comments

Comments
 (0)