microlinkhq / open

4 stars 2 forks source link

Custom Rules: Don't crash if some rule is malformed #3

Closed Kikobeats closed 5 years ago

Kikobeats commented 5 years ago

Originally reported by Stefan Charsley.

Current Behavior

If there is an error (for example a typo) in the selector of the custom rule then the server seems to crash and return a 404 not found.

Example

$ curl https://api.microlink.io/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F42718973%2Frun-avd-emulator-without-android-studio&data.image2.selector=.content-section+img:fisrt-of-type&data.image2.attr=src&data.image2.type=image

returns

{"status":"fail","message":"Scraping from \"https://stackoverflow.com/questions/42718973/run-avd-emulator-without-android-studio\" failed. Make sure your URL has HTML. Contact with hello@microlink.io."}

Here's an example (notice the spelling of the word first in the selector has a typo):

Kikobeats commented 5 years ago

Because we are considering adding a microlink-api code connector (https://github.com/microlinkhq/open/issues/5) probably this kind of validation has more sense to be done on the client library instead of adding more logic into API layer and making it slower.

charsleysa commented 5 years ago

@Kikobeats while the validation might be better to do client side, would it be possible to have a more descriptive error message so it's easier to identify the issue?

Kikobeats commented 5 years ago

That's true, let me identify kind of errors we are handling and create a list of well human errors message we can report