(window.webpackJsonp=window.webpackJsonp||[]).push([[10],{137:function(e,t,r){"use strict";r.r(t),r.d(t,"frontMatter",(function(){returni})),r.d(t,"metadata",(function(){returnl})),r.d(t,"rightToc",(function(){returnc})),r.d(t,"default",(function(){returnp}));varn=r(2),a=r(9),o=(r(0),r(186)),i={id:"retry_handling",title:"Retry Handling"},l={id:"retry_handling",title:"Retry Handling",description:"In Error Handling we already found out that requests can fail. We provide a way to automatically retry requests via retry handlers. Note, by default no retries are performed.",source:"@site/docs/retry_handling.md",permalink:"/SpotifyAPI-NET/docs/next/retry_handling",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/retry_handling.md",version:"next",lastUpdatedBy:"Jonas Dellinger",lastUpdatedAt:1594840510,sidebar:"docs",previous:{title:"Pagination",permalink:"/SpotifyAPI-NET/docs/next/pagination"},next:{title:"IPlayableItem",permalink:"/SpotifyAPI-NET/docs/next/iplayableitem"}},c=[{value:"SimpleRetryHandler",id:"simpleretryhandler",children:[]}],s={rightToc:c};functionp(e){vart=e.components,r=Object(a.a)(e,["components"]);returnObject(o.b)("wrapper",Object(n.a)({},s,r,{components:t,mdxType:"MDXLayout"}),Object(o.b)("p",null,"In ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"/SpotifyAPI-NET/docs/next/error_handling"}),"Error Handling")," we already found out that requests can fail. We provide a way to automatically retry requests via retry handlers. Note, by default no retries are performed."),Object(o.b)("pre",null,Object(o.b)("code",Object(n.a)({parentName:"pre"},{className:"language-csharp"}),"var config = SpotifyClientConfig\n .CreateDefault()\n .WithRetryHandler(new YourCustomRetryHandler())\n")),Object(o.b)("p",null,Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Http/Interfaces/IRetryHandler.cs"}),Object(o.b)("inlineCode",{parentName:"a"},"IRetryHandler"))," only needs one function:"),Object(o.b)("pre",null,Object(o.b)("code",Object(n.a)({parentName:"pre"},{className:"language-csharp"}),"public class YourCustomRetryHandler : IRetryHandler\n{\n public Task<IResponse> HandleRetry(IRequest request, IResponse response, IRetryHandler.RetryFunc retry)\n {\n // request is the sent request and response the received response, obviously?\n\n // don't retry:\n return response;\n\n // retry once\n var newResponse = retry(request);\n return newResponse;\n\n // use retry as often as you want, make sure to return a response\n }\n}\n")),Object(o.b)("h2",{id:"simpleretryhandler"},"SimpleRetryHandler"),Object(o.b)("p",null,"A ",Object(o.b)("inlineCode",{parentName:"p"},"SimpleRetryHandler")," is included, which contains the following retry logic:"),Object(o.b)("ul",null,Object(o.b)("li",{parentName:"ul"},"Retries the (configurable) status codes: 500, 502, 503 and 429"),Object(o.b)("li",{parentName:"ul"},Object(o.b)("inlineCode",{parentName:"li"},"RetryAfter")," - specifies the delay between retried calls"),Object(o.b)("li",{parentName:"ul"},Object(o.b)("inlineCode",{parentName:"li"},"RetryTimes")," - specifies the maxiumum amount of performed retries per call"),Object(o.b)("li",{parentName:"ul"},Object(o.b)("inlineCode",{parentName:"li"},"TooManyRequestsConsumesARetry"),' - Whether a failure of type "Too Many Requests" should use up one of the retry attempts.')),Object(o.b)("pre",null,Object(o.b)("code",Object(n.a)({parentName:"pre"},{className:"language-csharp"}),"var config = SpotifyClientConfig\n .CreateDefault()\n .WithRetryHandler(new SimpleRetryHandler() { RetryAfter = TimeSpan.FromSeconds(1) });\n\nvar spotify = new SpotifyClient(config);\n")))}p.isMDXComponent=!0},186:function(e,t,r){"use strict";r.d(t,"a",(function(){returnu})),r.d(t,"b",(function(){returnb}));varn=r(0),a=r.n(n);functiono(e,t,r){returntine?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}functioni(e,t){varr=Object.keys(e);if(Object.getOwnPropertySymbols){varn=Obj