nutgaard / yet-another-fetch-mock

MIT License
4 stars 2 forks source link

Throw exception if path not found #4

Closed alexander-svendsen closed 5 years ago

alexander-svendsen commented 6 years ago

Hi,

Perhaps this is not desired, but its worth a issue creation.

I want to see an more general error in the console when i'm using the mock lib on a path not configured and enableFallback: false

Now an JSON parse exception is thrown, because of the undefined response


utils.js:93 SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at Object.fetchmockMiddleware [as middleware] (utils.js:17)
    at yet-another-fetch-mock.es5.js:955 "SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at Object.fetchmockMiddleware [as middleware] (http://localhost:3000/aktivitetsplanfelles/bundle.js:27012:34)
    at http://localhost:3000/aktivitetsplanfelles/bundle.js:168050:40"
(anonymous) @ utils.js:93
Promise.catch (async)
(anonymous) @ utils.js:161
(anonymous) @ index.js:11
dispatch @ VM75:1
hentEnheter @ opprett-oppgave-form.js:166
onChange @ opprett-oppgave-form.js:80
onChange @ select.js:24
executeOnChange @ LinkedValueUtils.js:132
_handleChange @ ReactDOMSelect.js:190
ReactErrorUtils.invokeGuardedCallback @ ReactErrorUtils.js:69
executeDispatch @ EventPluginUtils.js:85
executeDispatchesInOrder @ EventPluginUtils.js:108
executeDispatchesAndRelease @ EventPluginHub.js:43
executeDispatchesAndReleaseTopLevel @ EventPluginHub.js:54
forEachAccumulated @ forEachAccumulated.js:24
processEventQueue @ EventPluginHub.js:257
runEventQueueInBatch @ ReactEventEmitterMixin.js:17
handleTopLevel @ ReactEventEmitterMixin.js:28
handleTopLevelImpl @ ReactEventListener.js:72
perform @ Transaction.js:140
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147 ```
alexander-svendsen commented 6 years ago

wobs i had forgotten to set enableFallback: false:P

alexander-svendsen commented 6 years ago

But is it possible for the mock library to log that it did not find a match and is defaulting to the real fetch method ?

alexander-svendsen commented 6 years ago

Maybe add the method (POST, GET etc) to the error msg when no path found ? Now i can configure a GET mock path to a POST and don't see a match, but only get an error message saying something about the url, which is the same

nutgaard commented 5 years ago

Solved in 2.4.1 (https://github.com/nutgaard/yet-another-fetch-mock/commit/a7e7e1a) Now logs a warning if fallback is enabled and no route-match is found, and added the http-verb to the existing error-message as well.