Translate unexpected errors into API-specific internal errors

@rlucioni