(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{151:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){returni})),n.d(t,"metadata",(function(){returnc})),n.d(t,"rightToc",(function(){returns})),n.d(t,"default",(function(){returnl}));varr=n(2),a=n(9),o=(n(0),n(187)),i={id:"error_handling",title:"Error Handling"},c={id:"error_handling",title:"Error Handling",description:"API calls can fail when input data is malformed or the server detects issues with the request. As an example, the following request obviously fails:",source:"@site/docs/error_handling.md",permalink:"/SpotifyAPI-NET/docs/next/error_handling",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/error_handling.md",version:"next",lastUpdatedBy:"Jonas Dellinger",lastUpdatedAt:1597925356,sidebar:"docs",previous:{title:"Getting Started",permalink:"/SpotifyAPI-NET/docs/next/getting_started"},next:{title:"Configuration",permalink:"/SpotifyAPI-NET/docs/next/configuration"}},s=[{value:"APIException",id:"apiexception",children:[]},{value:"APIUnauthorizedException",id:"apiunauthorizedexception",children:[]},{value:"APITooManyRequestsException",id:"apitoomanyrequestsexception",children:[]}],p={rightToc:s};functionl(e){vart=e.components,n=Object(a.a)(e,["components"]);returnObject(o.b)("wrapper",Object(r.a)({},p,n,{components:t,mdxType:"MDXLayout"}),Object(o.b)("p",null,"API calls can fail when input data is malformed or the server detects issues with the request. As an example, the following request obviously fails:"),Object(o.b)("pre",null,Object(o.b)("code",Object(r.a)({parentName:"pre"},{className:"language-csharp"}),'var track = await spotify.Tracks.Get("NotExistingTrackId");\nConsole.WriteLine(track.Name);\n')),Object(o.b)("p",null,"When a request fails an ",Object(o.b)("inlineCode",{parentName:"p"},"APIException")," is thrown. Specific errors may throw a child exception of ",Object(o.b)("inlineCode",{parentName:"p"},"APIException"),"."),Object(o.b)("h2",{id:"apiexception"},"APIException"),Object(o.b)("p",null,"A very general API error. The message is parsed from the API response JSON body and the response is available as public property."),Object(o.b)("pre",null,Object(o.b)("code",Object(r.a)({parentName:"pre"},{className:"language-csharp"}),'try {\n var track = await spotify.Tracks.Get("NotExistingTrackId");\n} catch(APIException e) {\n // Prints: invalid id\n Console.WriteLine(e.Message);\n // Prints: BadRequest\n Console.WriteLine(e.Response?.StatusCode);\n}\n')),Object(o.b)("h2",{id:"apiunauthorizedexception"},"APIUnauthorizedException"),Object(o.b)("p",null,"Provides the same properties as ",Object(o.b)("inlineCode",{parentName:"p"},"APIException")," and occurs, when the access token is expired or not provided. Notice that an access token has to be included in ",Object(o.b)("strong",{parentName:"p"},"every")," request. Spotify does not allow unauthorized API access."),Object(o.b)("h2",{id:"apitoomanyrequestsexception"},"APITooManyRequestsException"),Object(o.b)("p",null,"Provides the same properties as ",Object(o.b)("inlineCode",{parentName:"p"},"APIException")," and occurs, when too many requests has been sent by your application. It also provides the property ",Object(o.b)("inlineCode",{parentName:"p"},"TimeSpan RetryAfter"),", which maps to the received ",Object(o.b)("inlineCode",{parentName:"p"},"Retry-After")," Header."),Object(o.b)("pre",null,Object(o.b)("code",Object(r.a)({parentName:"pre"},{className:"language-csharp"}),'try {\n // call it very often?\n var track = await spotify.Tracks.Get("1s6ux0lNiTziSrd7iUAADH");\n} catch(APITooManyRequestsException e) {\n // Prints: seconds to wait, often 1 or 2\n Console.WriteLine(e.RetryAfter);\n}\n')))}l.isMDXComponent=!0},187:function(e,t,n){"use strict";n.d(t,"a",(function(){returnu})),n.d(t,"b",(function(){returnf}));varr=n(0),a=n.n(r);functiono(e,t,n){returntine?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}functioni(e,t){varn=Object.keys(e);if(Object.getOwnPropertySymbols){var