Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.conn.call("RFC_RAISE_ERROR", METHOD="1", MESSAGETYPE="E")
except pyrfc.ABAPApplicationError as ex:
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "RAISE_EXCEPTION"
assert error["msg_class"] == u"SR"
assert error["msg_type"] == "E"
assert error["msg_number"] == "006"
# Assures that the connection handle is correctly synchronized
self.conn.call("RFC_PING")
# '2_E': 'ABAPApplicationError-5-RAISE_EXCEPTION- Number:000-True',
# cf. ExceptionTest.c (l. 65ff)
try:
self.conn.call("RFC_RAISE_ERROR", METHOD="2", MESSAGETYPE="E")
except pyrfc.ABAPApplicationError as ex:
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "RAISE_EXCEPTION"
assert error["msg_number"] == "006"
self.conn.call("RFC_PING")
def my_sftc_connection_error(request_context, REQUTEXT):
# depending on the REQUTEXT value, raises errors.
if REQUTEXT == 'EXCEPTION':
raise ABAPApplicationError(key='BAD_EXCEPTION_HAPPENED')
elif REQUTEXT == 'EXCEPTION_MESSAGE':
raise ABAPApplicationError(key='BAD_EXCEPTION_W_MSG',
msg_class='SR', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='007', # 3 char numeric
msg_v1='V1 text' # 50 char
)
elif REQUTEXT == 'MESSAGE':
raise ABAPRuntimeError(
msg_class='SM', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='107', # 3 char numeric string
msg_v1='V1 text (ABAP_MESSAGE)'
)
elif REQUTEXT == 'FAILURE':
raise ExternalRuntimeError("Something very bad happened.")
def test_RFC_RAISE_ERROR_AbapApplicationError_E1(self):
# Comment: cf. result_print of the error_test.py
# '1_E': 'ABAPApplicationError-5-RAISE_EXCEPTION-ID:SR Type:E Number:006 STRING-True',
# cf. ExceptionTest.c (l. 75ff)
try:
self.conn.call("RFC_RAISE_ERROR", METHOD="1", MESSAGETYPE="E")
except pyrfc.ABAPApplicationError as ex:
assert self.conn.alive == True
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "RAISE_EXCEPTION"
assert error["msg_class"] == u"SR"
assert error["msg_type"] == "E"
assert error["msg_number"] == "006"
def test_call_non_existing_RFM(self):
try:
self.conn.call("undefined")
except pyrfc.ABAPApplicationError as ex:
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "FU_NOT_FOUND"
assert error["message"][0] == "ID:FL Type:E Number:046 undefined"
def my_sftc_connection_error(request_context, REQUTEXT):
# depending on the REQUTEXT value, raises errors.
if REQUTEXT == 'EXCEPTION':
raise ABAPApplicationError(key='BAD_EXCEPTION_HAPPENED')
elif REQUTEXT == 'EXCEPTION_MESSAGE':
raise ABAPApplicationError(key='BAD_EXCEPTION_W_MSG',
msg_class='SR', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='007', # 3 char numeric
msg_v1='V1 text' # 50 char
)
elif REQUTEXT == 'MESSAGE':
raise ABAPRuntimeError(
msg_class='SM', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='107', # 3 char numeric string
msg_v1='V1 text (ABAP_MESSAGE)'
)
elif REQUTEXT == 'FAILURE':
raise ExternalRuntimeError("Something very bad happened.")
elif REQUTEXT == 'INVALID':
raise RFCError("Invalid exception")
def test_server_error(self):
server = Server(config={'debug': True}, **config._sections['gateway'])
test = _Testing()
# Install two functions
func_desc_conn = self.conn.get_function_description("STFC_CONNECTION")
server.install_function(
func_desc_conn,
my_sftc_connection_error
)
with self.assertRaises(ABAPApplicationError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION")
self.assertEqual(run.exception.code, 5, "rc")
self.assertEqual(run.exception.key, "BAD_EXCEPTION_HAPPENED")
with self.assertRaises(ABAPApplicationError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION_MESSAGE")
self.assertEqual(run.exception.code, 5, "rc")
self.assertEqual(run.exception.key, "BAD_EXCEPTION_W_MSG")
self.assertEqual(run.exception.msg_class, "SR")
self.assertEqual(run.exception.msg_type, "E")
self.assertEqual(run.exception.msg_number, "007")
self.assertEqual(run.exception.msg_v1, "V1 text")
with self.assertRaises(ABAPRuntimeError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="MESSAGE")
self.assertEqual(run.exception.code, 4, "rc")