refactor with http-errors

cc @eivindfjeldstad @jonathanong