Set SQL error code for SPI errors raised from userland Python code.

If a PL/Python function was terminated by a SPIError raised from user
code, the Postgres-level error code was always set to internal_error.

This makes it pay attention to the exception's sqlstate attribute and
set the error code accordingly.