mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 14:35:03 +00:00
feat: bru.sendRequest api (#4867)
* feat: bru.sendRequest api * updated the postman-translations logic to handle `pm.sendRequest` to `bru.sendRequest` translations, and added unit tests * ~ removed `maxRedirects` and `proxy` values for sendRequest axios-instance ~ fixed the imports for the `send-request-transformer` function ~ `sendRequest` and `runRequest` will return same response object in both safe and developer mode ~ sendRequest function optimization * revert sendRequest to async function, added a testcase for sendRequest with url string * sendRequest callback errors handling * updated tests and added await for the callbacks --------- Co-authored-by: lohit <lohit@usebruno.com>
This commit is contained in:
1
packages/bruno-requests/src/scripting/index.ts
Normal file
1
packages/bruno-requests/src/scripting/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as sendRequest } from './send-request';
|
||||
30
packages/bruno-requests/src/scripting/send-request.ts
Normal file
30
packages/bruno-requests/src/scripting/send-request.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
import { makeAxiosInstance } from '../network';
|
||||
|
||||
type T_SendRequestCallback = (error: any, response: any) => void;
|
||||
|
||||
const sendRequest = async (requestConfig: AxiosRequestConfig, callback: T_SendRequestCallback) => {
|
||||
const axiosInstance = makeAxiosInstance();
|
||||
if (!callback) {
|
||||
return await axiosInstance(requestConfig);
|
||||
}
|
||||
try {
|
||||
const response = await axiosInstance(requestConfig);
|
||||
try {
|
||||
await callback(null, response);
|
||||
}
|
||||
catch(error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
try {
|
||||
await callback(error, null);
|
||||
}
|
||||
catch(err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default sendRequest;
|
||||
Reference in New Issue
Block a user