gosrc: handle not a directory error as not found error
We were correctly handling the error where the file did not exist by
mapping it to NotFoundError, which in turn was served as a normal 404
page to users. We were not handling the error where the file did exist
but was not a directory, which led to user-facing 500 errors.
This change fixes that by adding a check that the opened file is a
directory before attempting to read its contents.
Also, the file that was opened via os.Open was never closed. Fix that.
Reviewed-by: Tuo Shan <firstname.lastname@example.org>
1 file changed