Skip to content

Commit 6d513d7

Browse files
committed
Reduce string duplication in autodisovery code
1 parent 2fe7db9 commit 6d513d7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/autodiscovery.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ const parseLinkHeader = require( 'parse-link-header' );
1616
* @returns {String} The URL of the located API root
1717
*/
1818
function locateAPIRootHeader( response ) {
19+
// See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/
20+
const rel = 'https://api.w.org/';
21+
1922
// Extract & parse the response link headers
2023
const link = response.link || ( response.headers && response.headers.link );
2124
const headers = parseLinkHeader( link );
2225

23-
// See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/
24-
const apiHeader = headers && headers[ 'https://api.w.org/' ];
26+
const apiHeader = headers && headers[ rel ];
2527

2628
if ( apiHeader && apiHeader.url ) {
2729
return apiHeader.url;
2830
}
2931

30-
throw new Error( 'No header link found with rel="https://api.w.org/"' );
32+
throw new Error( `No header link found with rel="${ rel }"` );
3133
}
3234

3335
module.exports = {

0 commit comments

Comments
 (0)