Improve debug for error in api.go

Fixes #1189