Skip to content

Commit

Permalink
use await instead of then
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed May 11, 2023
1 parent 4c4046c commit 5fb4979
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re
return;
}

const handlerWrapper = (target, thisArg, args) => {
const handlerWrapper = async (target, thisArg, args) => {
let shouldPrevent = false;
const fetchData = getFetchData(args);
if (typeof propsToMatch === 'undefined') {
Expand All @@ -145,16 +145,14 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re

if (shouldPrevent) {
hit(source);
return Reflect.apply(target, thisArg, args)
.then((origResponse) => {
return modifyResponse(
origResponse,
{
body: strResponseBody,
type: responseType,
},
);
});
const origResponse = await Reflect.apply(target, thisArg, args);
return modifyResponse(
origResponse,
{
body: strResponseBody,
type: responseType,
},
);
}

return Reflect.apply(target, thisArg, args);
Expand Down

0 comments on commit 5fb4979

Please sign in to comment.