默认情况下,apiFetch将自动为您分析响应。您可以通过设置parse
到false
在apiFetch
选项,例如:
const handleClick = async () => {
try {
const result = await apiFetch( {
path: \'/your/path\',
parse: false,
} );
console.log( result ) // you will see ok status (e.g. 200) in here.
} catch ( error ) {
console.log( error ); // you will see error status (e.g. 404 or 500) in here.
}
};
更多信息:
apiFetch\'s parse option解析响应的相关代码:请参阅utils/response.js in apiFetch