Skip to content

Commit

Permalink
Merge pull request Expensify#17415 from Expensify/ionatan_manywrites
Browse files Browse the repository at this point in the history
Show alert when doing more than 1 write in auth in the backend
  • Loading branch information
AndrewGable authored Apr 14, 2023
2 parents 713c7ad + db627d0 commit fced26d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ const CONST = {
SUCCESS: 200,
NOT_AUTHENTICATED: 407,
EXP_ERROR: 666,
MANY_WRITES_ERROR: 665,
UNABLE_TO_RETRY: 'unableToRetry',
},
HTTP_STATUS: {
Expand Down
24 changes: 24 additions & 0 deletions src/components/Alert/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import _ from 'underscore';

/**
* Shows an alert modal with ok and cancel options.
*
* @param {String} title The title of the alert
* @param {String} description The description of the alert
* @param {Object[]} options An array of objects with `style` and `onPress` properties
*/
export default (title, description, options) => {
const result = _.filter(window.confirm([title, description], Boolean)).join('\n');

if (result) {
const confirmOption = _.find(options, ({style}) => style !== 'cancel');
if (confirmOption && confirmOption.onPress) {
confirmOption.onPress();
}
} else {
const cancelOption = _.find(options, ({style}) => style === 'cancel');
if (cancelOption && cancelOption.onPress) {
cancelOption.onPress();
}
}
};
3 changes: 3 additions & 0 deletions src/components/Alert/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Alert} from 'react-native';

export default Alert.alert;
4 changes: 4 additions & 0 deletions src/libs/HttpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
import HttpsError from './Errors/HttpsError';
import * as ApiUtils from './ApiUtils';
import alert from '../components/Alert';

let shouldFailAllRequests = false;
let shouldForceOffline = false;
Expand Down Expand Up @@ -94,6 +95,9 @@ function processHTTPRequest(url, method = 'get', body = null, canCancel = true,
title: CONST.ERROR_TITLE.SOCKET,
});
}
if (response.jsonCode === CONST.JSON_CODE.MANY_WRITES_ERROR) {
alert('Too many auth writes', 'The API call did more auth write requests than allowed. Check the APIWriteCommands class in Web-Expensify');
}
return response;
});
}
Expand Down

0 comments on commit fced26d

Please sign in to comment.