c# - What to do/throw when you have hit a API limit -


i using api limit, there high possibility hit limit.

i wondering how people handle this? check if hit limit , throw exception? if type of exception?

are there best practices?

i able see if hit limit below:

if (!string.isnullorempty(result.error))    {        // have hit limit    } 

this api used mvc application. caching actionresult methods api content ([outputcache]). if action method not recieve api result view empty, if throw end on custom errors page.

you should first log happened using information receive result.error , create custom exception , throw including original error message.

if (!string.isnullorempty(result.error)) {      // have hit limit      // log error      // throw new myexception(result.error); } 

normally can't in type of error log it, throw exception , it's somebody's else problem. when exception caught, decide, based on exception type, wait , retry.


Comments