log subnet for captchaserver, parse error response before caring about status code
This commit is contained in:
parent
c771e4a74d
commit
af90a83198
|
@ -32,8 +32,8 @@ async function fetchWithTimeout(resource, options) {
|
||||||
* @return Object of response
|
* @return Object of response
|
||||||
*/
|
*/
|
||||||
async function parseAPIresponse(response) {
|
async function parseAPIresponse(response) {
|
||||||
if (!response.ok) {
|
const { status: code } = response;
|
||||||
const code = response.status;
|
|
||||||
if (code === 429) {
|
if (code === 429) {
|
||||||
let error = t`You made too many requests`;
|
let error = t`You made too many requests`;
|
||||||
const retryAfter = response.headers.get('Retry-After');
|
const retryAfter = response.headers.get('Retry-After');
|
||||||
|
@ -45,16 +45,12 @@ async function parseAPIresponse(response) {
|
||||||
errors: [error],
|
errors: [error],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
errors: [t`Connection error ${code} :(`],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
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 promise from './promise';
|
||||||
import notifications from './notifications';
|
import notifications from './notifications';
|
||||||
import title from './title';
|
import title from './title';
|
||||||
|
import placePixelControl from './placePixelControl';
|
||||||
import extensions from './extensions';
|
import extensions from './extensions';
|
||||||
import reducers from '../reducers';
|
import reducers from '../reducers';
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ const store = createStore(
|
||||||
title,
|
title,
|
||||||
protocolClientHook,
|
protocolClientHook,
|
||||||
rendererHook,
|
rendererHook,
|
||||||
|
placePixelControl,
|
||||||
extensions,
|
extensions,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
20
src/store/placePixelControl.js
Normal file
20
src/store/placePixelControl.js
Normal file
|
@ -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 = {};
|
let lastRequestValues = {};
|
||||||
|
|
||||||
|
|
||||||
function requestFromQueue(store) {
|
export function requestFromQueue(store) {
|
||||||
if (!pixelQueue.length) {
|
if (!pixelQueue.length) {
|
||||||
pixelTimeout = null;
|
pixelTimeout = null;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -25,7 +25,7 @@ export function setCaptchaSolution(
|
||||||
text: string,
|
text: string,
|
||||||
ip: string,
|
ip: string,
|
||||||
) {
|
) {
|
||||||
const key = `capt:${getIPv6Subnet(ip)}`;
|
const key = `capt:${ip}`;
|
||||||
return redis.setAsync(key, text, 'EX', CAPTCHA_TIMEOUT);
|
return redis.setAsync(key, text, 'EX', CAPTCHA_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ export async function checkCaptchaSolution(
|
||||||
ip: string,
|
ip: string,
|
||||||
) {
|
) {
|
||||||
const ipn = getIPv6Subnet(ip);
|
const ipn = getIPv6Subnet(ip);
|
||||||
const key = `capt:${ipn}`;
|
const key = `capt:${ip}`;
|
||||||
const solution = await redis.getAsync(key);
|
const solution = await redis.getAsync(key);
|
||||||
if (solution) {
|
if (solution) {
|
||||||
if (solution.toString('utf8') === text) {
|
if (solution.toString('utf8') === text) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user