zotero / translation-server

A Node.js-based server to run Zotero translators
Other
122 stars 51 forks source link

Handles remote 4xx and 5xx responses and logs them #170

Closed foldleft closed 1 month ago

foldleft commented 1 month ago

At present if the remote service returns an error we get an undifferentiated 500 back from translation-server. This means we cannot distinguish between a 403, a 404 or a 500. This change allows us to log what happened.

Testing

I created a directory called nginx-force-response and populated conf.d/default.conf with a file like this (but with more entries):

server {
  listen 80;
  server_name localhost;
  location /401 {
    return 401;
  }
  location /501 {
    return 501;
  }
}

And then used it like so: docker run --rm --name nginx -v $PWD/conf.d:/etc/nginx/conf.d -p 8080:80 nginx

Finally, I was able to test like this:

$ curl -d 'http://127.0.0.1:8080/501' -H "content-type: text/plain" http://localhost:1969/web && echo
Remote server encountered an error handling our request (501)
$ curl -d 'http://127.0.0.1:8080/401' -H "content-type: text/plain" http://localhost:1969/web && echo
Remote server could not provide document (401)
foldleft commented 1 month ago

Hang on, I've got a lot of guff in here I didn't expect. Let me fix that and make a new PR...

foldleft commented 1 month ago

My apologies, I forgot to rebase against master – I had been adapting https://gerrit.wikimedia.org/r/c/mediawiki/services/zotero/+/1054354 for upstream. If you don't mind removing this PR, apparently repo owners can do so at https://support.github.com/contact?flow=pr_removal&subject=Delete%20Pull%20Request&tags=rr-remove-data