you can use the metric subsystem, adding a metric counting the 500 errors.
Metrics can have a threshold triggering an alarm (the reload in your case)
[uwsgi]
http-socket = :9092
; reload the instance when touching
touch-reload = /tmp/restart
; create a new alarm restarting the instance
alarm = database_reloaded cmd:touch /tmp/restart
; create a metric for couting 500s
metric = 500counter
; create a metric threshold, resetting the metric to 0 when hitting 5
; the metric alarm triggers the restart of the instance too
metric-alarm = key=500counter,value=5,alarm=database_reloaded,rate=60,reset=0
; increment metric whenever a 500 is generated
final-route-status = 500 metricinc:500counter