Bad Request Error
https://bessapay.net/errors/bad-requestOverview
A Bad Request error occurs when the request is malformed or contains invalid parameters. The server cannot process the request due to a client error.
Details
- Error Code: BAD_REQUEST
- HTTP Status: 400
- Error Type: Client Error
Common scenarios
- • Invalid parameter values
- • Missing required fields
- • Malformed JSON in request body
- • Incorrect data types
Example
Bad Request Error Response
1{
2 "type": "https://bessapay.net/errors/bad-request",
3 "title": "Bad Request",
4 "status": 400,
5 "detail": "The parameter 'amount' must be a positive number",
6 "instance": "/api/transactions",
7 "errorCode": "BAD_REQUEST",
8 "timestamp": "2023-06-15T10:15:30Z"
9}How to Fix
Check request parameters
Ensure all parameters match the requirements in the API documentation. Check for correct data types, valid formats, and required fields.
Validate request body
Make sure your JSON is well-formed and contains all required fields. Use a JSON validator to check for syntax errors.
Check for proper encoding
Ensure special characters are properly encoded, especially in URLs. Use URL encoding for query parameters.
Implement client-side validation
Add validation to your client application to catch common errors before sending requests to the API.
Code Example: Handling Bad Request Errors
JavaScript Error Handling
1// Example of handling Bad Request errors
2async function createTransaction(transactionData) {
3 try {
4 const response = await fetch('https://api.semuni.com/v1/transactions', {
5 method: 'POST',
6 headers: {
7 'Content-Type': 'application/json',
8 'X-API-Key': 'your_api_key_here'
9 },
10 body: JSON.stringify(transactionData)
11 });
12
13 if (!response.ok) {
14 const errorData = await response.json();
15
16 if (errorData.type === 'https://bessapay.net/errors/bad-request') {
17 console.error(`Bad Request Error: ${errorData.detail}`);
18
19 // Handle specific bad request scenarios
20 if (errorData.detail.includes('amount')) {
21 // Show specific error for amount field
22 showFieldError('amount', 'Please enter a valid positive number');
23 } else {
24 // Show generic error
25 showError(errorData.detail);
26 }
27
28 return null;
29 }
30
31 // Handle other error types
32 throw new Error(errorData.detail || 'An error occurred');
33 }
34
35 const data = await response.json();
36 return data;
37 } catch (error) {
38 console.error('Transaction creation failed:', error);
39 throw error;
40 }
41}