encapsulated error json response in single function and added stubs for message manipulation