Skip to content

fix: Example: Safe Mutation with Idempotent POST Requests - #68

Open
webbrain-one wants to merge 1 commit into
cinar:mainfrom
webbrain-one:webbrain/issue-49
Open

webbrain-one wants to merge 1 commit into
cinar:mainfrom
webbrain-one:webbrain/issue-49

Conversation

@webbrain-one

Copy link
Copy Markdown

Closes #49

Demonstrate safe retries for state-changing requests by reusing a single idempotency key and retrying only 5xx statuses, not 4xx business-logic errors.

@cinar cinar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your contribution! I added few minor comments. Please let me know what do you think.

fmt.Println("\nUnexpected: terminal scenario succeeded instead of returning 400.")
}

func executeSafePOST(ctx context.Context, client *http.Client, url string, payload string, maxAttempts int) error {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The executeSafePOST declares maxAttempts as int but passes it directly to resile.WithMaxAttempts, which requires uint. Perhaps you can change it here as well?

{"wrapped transport", fmt.Errorf("request failed: %w", errors.New("connection reset by peer")), true},
{"500", &HTTPError{StatusCode: http.StatusInternalServerError}, true},
{"502", &HTTPError{StatusCode: http.StatusBadGateway}, true},
{"504", &HTTPError{StatusCode: http.StatusGatewayTimeout}, true},

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is skipping 503 (Service Unavailable) intentional? Would you like to include it here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Example: Safe Mutation with Idempotent POST Requests

2 participants