diff --git a/index.js b/index.js index bb050802..7ed5c3a0 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,13 @@ import {INVALID_REQUEST} from './lib/errors.js' import {sliceLeg} from './lib/slice-leg.js' import {HafasError} from './lib/errors.js' +// background info: https://github.com/public-transport/hafas-client/issues/286 +const FORBIDDEN_USER_AGENTS = [ + 'my-awesome-program', // previously used in readme.md, p/*/readme.md & docs/*.md + 'hafas-client-example', // previously used in p/*/example.js + 'link-to-your-project-or-email', // now used throughout +] + const isNonEmptyString = str => 'string' === typeof str && str.length > 0 const validateLocation = (loc, name = 'location') => { @@ -35,6 +42,9 @@ const createClient = (profile, userAgent, opt = {}) => { if ('string' !== typeof userAgent) { throw new TypeError('userAgent must be a string'); } + if (FORBIDDEN_USER_AGENTS.includes(userAgent.toLowerCase())) { + throw new TypeError(`userAgent should tell the HAFAS API operators how to contact you. If you have copied "${userAgent}" value from the documentation, please adapt it.`); + } const _stationBoard = async (station, type, resultsField, parse, opt = {}) => { if (isObj(station)) station = profile.formatStation(station.id) diff --git a/readme.md b/readme.md index 465d0473..5b80ee77 100644 --- a/readme.md +++ b/readme.md @@ -53,7 +53,8 @@ Because the operatores of the HAFAS endpoint should be able to contact you about import {createClient} from 'hafas-client' import {profile as dbProfile} from 'hafas-client/p/db/index.js' -const userAgent = 'link-to-your-project-or-email' // adapt this to your project! +// Adapt this to your project! createClient() won't work with this string. +const userAgent = 'link-to-your-project-or-email' // create a client with the Deutsche Bahn profile const client = createClient(dbProfile, userAgent)