|
1 | 1 | import type { Placement } from './compute-position'; |
2 | 2 | import computePosition from './compute-position'; |
3 | 3 | import { escUrl, escHtml } from './sanitizer'; |
| 4 | +import addQueryArg from './add-query-arg'; |
4 | 5 | import __ from './i18n'; |
5 | 6 |
|
6 | 7 | interface AccountData { |
@@ -255,7 +256,7 @@ export default class Hovercards { |
255 | 256 | const hovercard = dc.createElement( 'div' ); |
256 | 257 | hovercard.className = `gravatar-hovercard${ additionalClass ? ` ${ additionalClass }` : '' }`; |
257 | 258 |
|
258 | | - const trackedProfileUrl = escUrl( `${ profileUrl }?utm_source=hovercard` ); |
| 259 | + const trackedProfileUrl = escUrl( addQueryArg( profileUrl, 'utm_source', 'hovercard' ) ); |
259 | 260 | const username = escHtml( displayName ); |
260 | 261 | const isEditProfile = ! description && myHash === hash; |
261 | 262 | const renderSocialLinks = verifiedAccounts |
@@ -411,7 +412,7 @@ export default class Hovercards { |
411 | 412 |
|
412 | 413 | this._onFetchProfileStart( hash ); |
413 | 414 |
|
414 | | - fetch( `${ BASE_API_URL }/${ hash }?source=hovercard` ) |
| 415 | + fetch( addQueryArg( `${ BASE_API_URL }/${ hash }`, 'source', 'hovercard' ) ) |
415 | 416 | .then( ( res ) => { |
416 | 417 | // API error handling |
417 | 418 | if ( res.status !== 200 ) { |
@@ -457,12 +458,16 @@ export default class Hovercards { |
457 | 458 | .catch( ( code ) => { |
458 | 459 | let message = __( this._i18n, 'Sorry, we are unable to load this Gravatar profile.' ); |
459 | 460 |
|
460 | | - if ( code === 429 ) { |
461 | | - message = __( this._i18n, 'Too Many Requests.' ); |
462 | | - } |
463 | | - |
464 | | - if ( code === 500 ) { |
465 | | - message = __( this._i18n, 'Internal Server Error.' ); |
| 461 | + switch ( code ) { |
| 462 | + case 404: |
| 463 | + message = __( this._i18n, 'Profile not found.' ); |
| 464 | + break; |
| 465 | + case 429: |
| 466 | + message = __( this._i18n, 'Too Many Requests.' ); |
| 467 | + break; |
| 468 | + case 500: |
| 469 | + message = __( this._i18n, 'Internal Server Error.' ); |
| 470 | + break; |
466 | 471 | } |
467 | 472 |
|
468 | 473 | const hovercardInner = Hovercards.createHovercardError( |
|
0 commit comments