Repository: mdn/kuma

Issue:
T - TypeError 'count.toLocaleString' in SSR
https://sentry.prod.mozaws.net/operations/mdn-prod/issues/7090931/

```
TypeError: Cannot read property 'toLocaleString' of undefined
  File "/app/kuma/javascript/dist/ssr.js", line 22, in kt
    '{snip} ocuments found for "%(query)s" in %(locale)s.',a),{count:a.toLocaleString(),locale:n,query:c})," ",t))}function jt(e){var t=e.locale;return( {snip}
  File "/app/kuma/javascript/dist/ssr.js", line 22, in a
    '{snip} .state);null!=d&&(f.state=r({},f.state,d))}}else if(D={},f=a(o.props,i,s),null==(f=G(a,o.props,f,i))||null==f.render)return void he(e=f,a);i {snip}
  File "/app/kuma/javascript/dist/ssr.js", line 22, in ye
    '{snip} lement(e);){var i=e,c=i.type;if("function"!=typeof c)break;a(i,c)}return{child:e,context:t}}var ve=function(){function e(t,n){if(!(this inst {snip}
  File "/app/kuma/javascript/dist/ssr.js", line 22, in e.render
    '{snip} -- --\x3e"+I(n):(this.previousWasTextNode=!0,I(n));if(e=(t=ye(e,t,this.threadID)).child,t=t.context,null===e||!1===e)return"";if(!o.isValidE {snip}
  File "/app/kuma/javascript/dist/ssr.js", line 22, in e.read
    '{snip} +=c}else{var f=i.children[i.childIndex++],m="";try{m+=this.render(f,i.context,i.domNamespace)}catch(e){throw e}r.length<=this.suspenseDepth& {snip}
...
(5 additional frame(s) were not displayed)
```


Discussion:
Sadly, the Sentry event is pretty hard to debug. 
But does contain this:
```
'{snip} ocuments found for "%(query)s" in %(locale)s.',a),{count:a.toLocaleString(),locale:n,query:c})," ",t))}function jt(e){var t=e.locale;return( {snip}
```
which looks like it might be the minified/babelified-to-es5 version of https://github.com/mdn/kuma/blob/d80b6668792f01a4826b33ab9d082426911b1768/kuma/javascript/src/search-results-page.jsx#L76

So it's probably a bad search result. 

If only we could figure out what the URL was we could figure out what they tried to search for. 
A more pressing concern is how poor the Sentry event is :(
Where is the context not mentioning a URL??
Won't fix for now because it's a rare occurence.
Yay!! Able to reproduce it!
http://localhost.org:8000/ja/search?page=350&q=example
It happens when you over set the the `page` to a number that is too large. 
Note-to-self; you (today) get the same error with https://developer.mozilla.org/en-US/search?page=3&q=intersectionobserver (I manually put in the page=3 because there was no "Next" button on page=2) 

Resolving patch:
diff --git a/kuma/search/views.py b/kuma/search/views.py
--- a/kuma/search/views.py
+++ b/kuma/search/views.py
@@ -33,6 +33,10 @@ def search(request, *args, **kwargs):
     # If q is returned in the data, there was a validation error for that field,
     # so return 400 status.
     status = 200 if results.get("q") is None else 400
+    # If there was an error with the pagination you'll get...
+    if results.get("detail"):
+        error = str(results["detail"])
+        status = 400
 
     context = {"results": {"results": None if error else results, "error": error}}
 


Test patch:
diff --git a/kuma/search/tests/test_views.py b/kuma/search/tests/test_views.py
--- a/kuma/search/tests/test_views.py
+++ b/kuma/search/tests/test_views.py
@@ -166,6 +166,14 @@ def test_paginate_too_large(self):
         # rest_framework works.
         assert response.status_code == 404
 
+    def test_page_too_large(self):
+        # Note that this doesn't use the Wiki host
+        response = self.client.get("/en-US/search", {"page": 2, "q": "anything"})
+        # The search 'q' is fine and the page isn't too large on its own, but
+        # the pagination doesn't go beyond the first page so the rest_frameworks
+        # pagination will trigger an error.
+        assert response.status_code == 400
+
     def test_tokenize_camelcase_titles(self):
         for q in ("get", "element", "by", "id"):
             response = self.client.get(