use-http icon indicating copy to clipboard operation
use-http copied to clipboard

Data not set to default value when an error is returned

Open finnshort opened this issue 4 years ago • 0 comments

Describe the bug If the data option is set to an empty array as the default value, I would expect to get the default value if the request returns an error. Instead 'data' is set to response.data whether there's an error or not. Is this the intended behaviour, is there a way I can keep the default empty array value if there's an error? ⚠️ Make a Codesandbox ⚠️ Please do this to easily reproduce the bug. https://codesandbox.io/s/usefetch-provider-requestresponse-interceptors-forked-fh7mz?file=/src/index.js

To Reproduce Steps to reproduce the behavior: see browser output when useFetch tries to access resource that doesn't exist- code tries to parse and display error message as data

Expected behavior A clear and concise description of what you expected to happen. I would just expect to see 'error.message' in the browser, 'loading' and 'data' would not display anything

finnshort avatar Jan 28 '21 23:01 finnshort