File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -65,18 +65,20 @@ export default class CratesClient {
6565 static BASE_URL = 'https://crates.io/api/v1'
6666
6767 static async crate ( crate : string ) : Promise < CrateInfoResponse | null > {
68- const url = `${ CratesClient . BASE_URL } /crates/${ crate } `
69- const resp = await fetch ( url )
70-
71- if ( resp . status !== 200 ) return null
72- return await resp . json < CrateInfoResponse > ( )
68+ return await this . request ( `${ CratesClient . BASE_URL } /crates/${ crate } ` )
7369 }
7470
7571 static async versions ( crate : string ) : Promise < CrateVersionResponse | null > {
76- const url = `${ CratesClient . BASE_URL } /crates/${ crate } /versions`
77- const resp = await fetch ( url )
72+ return await this . request ( `${ CratesClient . BASE_URL } /crates/${ crate } /versions` )
73+ }
7874
75+ private static async request < T > ( url : string ) : Promise < T | null > {
76+ const resp = await fetch ( url , {
77+ headers : {
78+ 'User-Agent' : 'spacebadgers-badge-agent (badgers.space)'
79+ }
80+ } )
7981 if ( resp . status !== 200 ) return null
80- return await resp . json < CrateVersionResponse > ( )
82+ return await resp . json < T > ( )
8183 }
8284}
You can’t perform that action at this time.
0 commit comments