services: pki-resource: send proper http code when exception

open writer only after validations.

Change-Id: Idf4c5157bf7425da5f9bb0d5186c48b4b9cc313c
Signed-off-by: Alon Bar-Lev <alonbl@redhat.com>