mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
1 line
5.8 KiB
JavaScript
1 line
5.8 KiB
JavaScript
|
(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{151:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return c})),n.d(t,"rightToc",(function(){return s})),n.d(t,"default",(function(){return l}));var r=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:"Nova",lastUpdatedAt:1599917131,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};function l(e){var t=e.components,n=Object(a.a)(e,["components"]);return Object(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(){return u})),n.d(t,"b",(function(){return f}));var r=n(0),a=n.n(r);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.ge
|