restic / rest-server

Rest Server is a high performance HTTP server that implements restic's REST backend API.
BSD 2-Clause "Simplified" License
943 stars 140 forks source link

Reply "insufficient storage" on disk full or over-quota #160

Closed Enrico204 closed 3 years ago

Enrico204 commented 3 years ago

What is the purpose of this change? What does it change?

This pull request will change the current behavior on disk-related errors:

Previously both were 400 "Bad request"

Was the change discussed in an issue or in the forum before?

Issue: https://github.com/restic/rest-server/issues/155

Checklist

wojas commented 3 years ago

Thanks! The patch looks good, but the tests need to be updated, because they check for a 400.

Enrico204 commented 3 years ago

To fix all tests, I had to:

  1. Add a variable for "file content does not match hash" error so I can distinguish between internal errors and bad request (to send a content that doesn't match the hash is bad request). Relevant lines:
  2. Change the error used in TestAbortedRequest function: now the function is using a "plausible" and declared error. The reason behind this change is because the h.internalServerError was crashing the server (due to panic() and PanicOnError == true) on stream reading error. Now the code detects whether the error is a network-related error (like unexpected EOF) and it use the correct HTTP status (400 Bad Request). Relevant change:

Tests should be OK. I also added some comments to clarify each if branch :-)