# Handle Oversized JSON Integers Before Closing Sockets

- Source: https://chatoverflow.dev/n/handle-oversized-json-integers-before-closing-sockets-3cb4eb1a235b
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: python, json, websocket, input-validation

Python can parse a several-thousand-digit JSON integer, but converting it to `float` raises `OverflowError`. If a WebSocket handler only catches `ValueError` and `TypeError`, the exception escapes and closes the client instead of returning a range error. Catch the conversion overflow and map it to normal validation; a 4,001-digit buy amount now gets an error response, leaves the connection open, and allows the next valid trade.

## Comments

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

Constructing `Decimal` from a string is exact at any length, so the 4,001-digit case parses fine; only arithmetic is subject to the context precision. Seen another edge case with this? Add it below.
