Add generic http error handling

Close issue #12