Skip to content

Commit 2468023

Browse files
authored
add error type for 429 too many requests (#62)
1 parent 26f6c57 commit 2468023

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/components/simulation/Error.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import GeneralErrorComponent from './SimulationSubComponents/errors/GeneralError
1010
import InsufficientFundsComponent from './SimulationSubComponents/errors/InsufficientFundsError';
1111
import RevertComponent from './SimulationSubComponents/errors/RevertError';
1212
import UnauthorizedComponent from './SimulationSubComponents/errors/UnauthorizedError';
13+
import RateLimitedError from './SimulationSubComponents/errors/RateLimitedError';
1314

1415
interface ErrorComponentProps {
1516
currentSimulation: StoredSimulation;
@@ -32,6 +33,8 @@ export const ErrorComponent = (props: ErrorComponentProps) => {
3233
return <InsufficientFundsComponent currentSimulation={currentSimulation} />;
3334
case ErrorType.Revert:
3435
return <RevertComponent currentSimulation={currentSimulation} />;
36+
case ErrorType.TooManyRequests:
37+
return <RateLimitedError currentSimulation={currentSimulation} />;
3538
default:
3639
return <GeneralErrorComponent currentSimulation={currentSimulation} />;
3740
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import styles from '../../simulation.module.css';
3+
import ErrorTextComponent from './ErrorText';
4+
import { ErrorComponentProps } from './GeneralError';
5+
6+
export default function RateLimitedError(props: ErrorComponentProps) {
7+
return (
8+
<div className="row pt-5 text-center pl-4 pr-4">
9+
<div className="col-12">
10+
<h4 className={`${styles['font-archivo-medium']} pb-3`} style={{ color: 'white', marginBottom: '20px' }}>
11+
Too many requests
12+
</h4>
13+
</div>
14+
<div className="col-12 text-center">
15+
<p
16+
className={`${styles['font-archivo-medium']}`}
17+
style={{
18+
color: 'white',
19+
fontSize: '16px',
20+
}}
21+
>
22+
We've received a lot of requests recently. Please try again in an hour.
23+
</p>
24+
</div>
25+
<ErrorTextComponent currentSimulation={props.currentSimulation} />
26+
</div>
27+
);
28+
}

src/lib/simulation/server.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export const fetchSimulate = async (args: TransactionArgs): Promise<Response> =>
4141
extraData: null
4242
}
4343
};
44+
} else if (result.status === 429) {
45+
return {
46+
type: ResponseType.Error,
47+
error: {
48+
type: ErrorType.TooManyRequests,
49+
message: "TooManyRequests",
50+
extraData: null
51+
}
52+
}
4453
}
4554

4655
const data: SimulationErrorResponse = await result.json();
@@ -99,6 +108,15 @@ export const fetchSignature = async (
99108
extraData: null
100109
}
101110
};
111+
} else if (result.status === 429) {
112+
return {
113+
type: ResponseType.Error,
114+
error: {
115+
type: ErrorType.TooManyRequests,
116+
message: "TooManyRequests",
117+
extraData: null
118+
}
119+
}
102120
}
103121

104122
const data: SimulationErrorResponse = await result.json();

src/models/simulation/Transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export enum ErrorType {
101101
InsufficientFunds = 'INSUFFICIENT_FUNDS',
102102
MaxFeePerGasLessThanBlockBaseFee = 'MAX_FEE_PER_GAS_LESS_THAN_BLOCK_BASE_FEE',
103103
Revert = 'REVERT',
104+
TooManyRequests = 'TOO_MANY_REQUESTS',
104105
GeneralError = 'ERROR',
105106
UnknownError = "UNKNOWN_ERROR"
106107
}

0 commit comments

Comments
 (0)