keithjgrant / omnibear

A Micropub browser extension
MIT License
36 stars 8 forks source link

Incorrectly reporting http 500 replies as "successfully posted" #32

Closed keithjgrant closed 6 years ago

keithjgrant commented 6 years ago

I got a 500 from my micropub endpoint, but it displayed the normal "successfully posted" message, which is obviously incorrect. Something is slipping through the error handling for that request.

grantcodes commented 6 years ago

Yeah I just started noticing that too. It is because I didn't realise fetch will still resolve even if the http status is an error. I guess I may have to check the status codes in my micropub library

keithjgrant commented 6 years ago

Yeah, fetch only "fails" if the network request itself actually fails. You have to handle HTTP response codes separately. Make sure the micropub library exposes the response code somehow, so I can distinguish 500 codes from 400 codes.

grantcodes commented 6 years ago

Ok I have a new version of the micropub-helper library up on npm (1.2.1)

In this version it will throw errors if the endpoint doesn't return a 2xx status code.

Errors now come as objects like this:

{
  message: 'Human readable string',
  status: null or the http status code,
  error: null or further error information,
}

So you will be able to read if err.status is a 400 or 500 and do whatever you want.

Just let me know if you run into any problems or have questions.

grantcodes commented 6 years ago

So the micropub-helper update means that this will default to being an error and omnibear will flash the error message

keithjgrant commented 6 years ago

Marking this resolved. I believe it's working now.