Specifically to New york : the landlord needs to send you a notice via mail that you didn't pay rent in the 5 day after you were supposed to pay,they need to do it EVERY TIME and if they don't,you can use it against them in court
They need to send you a WRITTEN notice 14 day in advance asking for the rest of the debt (and writing every month and the exact amount you owe them) before sending you to court,they need to write a paper explicitely for everybody involved in the case (this can give you some time if they didn't do it correctly)
you can argue to have the eviction delayed for at most a year during the court if you say you can't find another housing close to you.
if you pay the debt during that year,the case gets dismissed automatically
IANAL,you should check lawhelp and consult with someone there,and you should also check if you can get help to repay your debt via 211
I'm not a USAnian btw,I just followed this paper :
https://nycourts.gov/courthelp/pdfs/TenantsGuide_nonpayment.pdf