fix(engines): cap Brave API offset to 9 to avoid 422 error
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6s
Mirror to GitHub / mirror (push) Failing after 3s
Tests / test (push) Successful in 24s

Brave API only supports offset values 0-9. When pageno > 1 with
resultsPerPage=20, offset exceeded this limit causing 422 errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ashisgreat22 2026-03-22 12:41:42 +01:00 committed by Franz Kafka
parent 3bc1fad6b5
commit f172da33ef

View file

@ -80,10 +80,15 @@ func (e *BraveEngine) Search(ctx context.Context, req contracts.SearchRequest) (
return contracts.SearchResponse{Query: req.Query}, nil return contracts.SearchResponse{Query: req.Query}, nil
} }
// Brave API only supports offset values 0-9 (first page of results).
// Paginating beyond the first page is not supported by Brave.
offset := 0 offset := 0
if req.Pageno > 1 { if req.Pageno > 1 {
offset = (req.Pageno - 1) * e.resultsPerPage offset = (req.Pageno - 1) * e.resultsPerPage
} }
if offset > 9 {
offset = 9
}
args := url.Values{} args := url.Values{}
args.Set("q", q) args.Set("q", q)