log subnet for captchaserver, parse error response before caring about status code
This commit is contained in:
parent
c771e4a74d
commit
af90a83198
|
@ -32,21 +32,17 @@ async function fetchWithTimeout(resource, options) {
|
|||
* @return Object of response
|
||||
*/
|
||||
async function parseAPIresponse(response) {
|
||||
if (!response.ok) {
|
||||
const code = response.status;
|
||||
if (code === 429) {
|
||||
let error = t`You made too many requests`;
|
||||
const retryAfter = response.headers.get('Retry-After');
|
||||
if (!Number.isNaN(Number(retryAfter))) {
|
||||
const ti = Math.floor(retryAfter / 60);
|
||||
error += `, ${t`try again after ${ti}min`}`;
|
||||
}
|
||||
return {
|
||||
errors: [error],
|
||||
};
|
||||
const { status: code } = response;
|
||||
|
||||
if (code === 429) {
|
||||
let error = t`You made too many requests`;
|
||||
const retryAfter = response.headers.get('Retry-After');
|
||||
if (!Number.isNaN(Number(retryAfter))) {
|
||||
const ti = Math.floor(retryAfter / 60);
|
||||
error += `, ${t`try again after ${ti}min`}`;
|
||||
}
|
||||
return {
|
||||
errors: [t`Connection error ${code} :(`],
|
||||
errors: [error],
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -54,7 +50,7 @@ async function parseAPIresponse(response) {
|
|||
return await response.json();
|
||||
} catch (e) {
|
||||
return {
|
||||
errors: [t`Server answered with gibberish :(`],
|
||||
errors: [t`Connection error ${code} :(`],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import array from './array';
|
|||
import promise from './promise';
|
||||
import notifications from './notifications';
|
||||
import title from './title';
|
||||
import placePixelControl from './placePixelControl';
|
||||
import extensions from './extensions';
|
||||
import reducers from '../reducers';
|
||||
|
||||
|
@ -29,6 +30,7 @@ const store = createStore(
|
|||
title,
|
||||
protocolClientHook,
|
||||
rendererHook,
|
||||
placePixelControl,
|
||||
extensions,
|
||||
),
|
||||
),
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Hooks for placePixel
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import { requestFromQueue } from '../ui/placePixel';
|
||||
|
||||
export default (store) => (next) => (action) => {
|
||||
switch (action.type) {
|
||||
case 'CLOSE_ALERT': {
|
||||
requestFromQueue(store);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// nothing
|
||||
}
|
||||
|
||||
return next(action);
|
||||
};
|
|
@ -38,7 +38,7 @@ let clientPredictions = [];
|
|||
let lastRequestValues = {};
|
||||
|
||||
|
||||
function requestFromQueue(store) {
|
||||
export function requestFromQueue(store) {
|
||||
if (!pixelQueue.length) {
|
||||
pixelTimeout = null;
|
||||
return;
|
||||
|
|
|
@ -25,7 +25,7 @@ export function setCaptchaSolution(
|
|||
text: string,
|
||||
ip: string,
|
||||
) {
|
||||
const key = `capt:${getIPv6Subnet(ip)}`;
|
||||
const key = `capt:${ip}`;
|
||||
return redis.setAsync(key, text, 'EX', CAPTCHA_TIMEOUT);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ export async function checkCaptchaSolution(
|
|||
ip: string,
|
||||
) {
|
||||
const ipn = getIPv6Subnet(ip);
|
||||
const key = `capt:${ipn}`;
|
||||
const key = `capt:${ip}`;
|
||||
const solution = await redis.getAsync(key);
|
||||
if (solution) {
|
||||
if (solution.toString('utf8') === text) {
|
||||
|
|
Loading…
Reference in New Issue