问题
In my API class, I have a code like below,
let response;
try {
response = await fetch(requestUrl, {
method: 'POST',
headers,
timeout: REQUEST_TIMEOUT_MS,
body: JSON.stringify({
id,
accNumber: acctId,
invNumber: invId,
fromDate,
toDate
})
});
} catch (error) {
throw new Error(
'Unexpected error occurred while invoking ATOM Invoice API',
error
);
}
foo(cloneDeep(response));
const result = await response.json();
--- some more code ---
Then in another class, I have implemented foo
method,
async foo(response){
let result;
let errorDescription;
try {
result = await response.json();
} catch (error) {
logger.error(JSON.stringify(error));
}
--- some more code ---
}
When running the above code I get the following error thrown from foo
function:
{
"name": "FetchError",
"message": "response timeout at <my request URL in here> over limit: 10000",
"type": "body-timeout"
}
I would like to know why this happens and what should I do to avoid this. Thanks in advance!
来源:https://stackoverflow.com/questions/50460134/fetch-error-when-calling-response-json