(xhr)
| 1452 | |
| 1453 | let isRetry = false |
| 1454 | let handleError = function(xhr) { |
| 1455 | let { status } = xhr |
| 1456 | let title = '' |
| 1457 | let message = '' |
| 1458 | |
| 1459 | switch (status) { |
| 1460 | case 0: |
| 1461 | if (isRetry) { |
| 1462 | title = 'Connection error' |
| 1463 | message = 'Please try again later.' |
| 1464 | } else { |
| 1465 | // next request should be retry |
| 1466 | isRetry = true |
| 1467 | request() |
| 1468 | return |
| 1469 | } |
| 1470 | break |
| 1471 | case 401: |
| 1472 | title = 'Invalid token' |
| 1473 | message = encodeHTML`<a href="${CREATE_TOKEN_PATH}" class="ghh-token-link" target="_blank">Create a new access token</a>, <a href="#" class="ghh-token-link">paste it back here</a> and try again.` |
| 1474 | break |
| 1475 | case 403: { |
| 1476 | let response = xhr.responseJSON |
| 1477 | if ( |
| 1478 | xhr |
| 1479 | .getAllResponseHeaders() |
| 1480 | .indexOf('X-RateLimit-Remaining: 0') !== -1 |
| 1481 | ) { |
| 1482 | title = 'API rate limit exceeded' |
| 1483 | if (!localStorage.getItem(TOKEN_KEY)) { |
| 1484 | message = encodeHTML`API rate limit exceeded for current IP. <a href="${CREATE_TOKEN_PATH}" class="ghh-token-link" target="_blank">Create a new access token</a> and <a href="#" class="ghh-token-link">paste it back here</a> to get a higher rate limit.` |
| 1485 | } |
| 1486 | } else if ( |
| 1487 | type === EXTRACT_TYPE.REPO && |
| 1488 | response.block && |
| 1489 | response.block.reason === 'tos' |
| 1490 | ) { |
| 1491 | title = 'Access blocked' |
| 1492 | message = encodeHTML`Access to this repository has been disabled by GitHub staff.` |
| 1493 | } else { |
| 1494 | title = 'Forbidden' |
| 1495 | message = encodeHTML`You are not allowed to access GitHub API. <a href="${CREATE_TOKEN_PATH}" class="ghh-token-link" target="_blank">Create a new access token</a>, <a href="#" class="ghh-token-link">paste it back here</a> and try again.` |
| 1496 | } |
| 1497 | break |
| 1498 | } |
| 1499 | case 404: |
| 1500 | title = 'Not found' |
| 1501 | if (type === EXTRACT_TYPE.REPO || type === EXTRACT_TYPE.ISSUE) { |
| 1502 | message = encodeHTML`The repository doesn't exist or is private. <a href="${CREATE_TOKEN_PATH}" class="ghh-token-link" target="_blank">Create a new access token</a>, <a href="#" class="ghh-token-link">paste it back here</a> and try again.` |
| 1503 | } else if (type === EXTRACT_TYPE.USER) { |
| 1504 | message = "The user doesn't exist." |
| 1505 | } |
| 1506 | break |
| 1507 | case 451: { |
| 1508 | let response = xhr.responseJSON |
| 1509 | if ( |
| 1510 | type === EXTRACT_TYPE.REPO && |
| 1511 | response.block && |
nothing calls this directly
no test coverage detected