Fake error with custom type and message

Hi,

Instead of throwing errors by parsing invalid JSON I thought I’d try using a custom module, so I made one that has no URL defined (base or otherwise), takes for inputs an assertion, an error type and an error message, with a definition like so:

{
	"response": {
		"valid": "{{parameters.assertion}}",
		"error": {
			"type": "DataError",
			"200": {
				"message": "[200] Test"
			},
			"message": "{{parameters.errorMessage}}"
		},
		"output": { }
	}
}

The actual assertion/validation works; the module throws an error when the assertion is false, but the error parameters seem to be ignored. I hardcoded the type to verify whether it was an issue with using a parameter, and I added the 200 object to see whether it made a difference, but the error thrown is always the following:

RuntimeError

Response marked as invalid.

Am I specifying the error parameters incorrectly, or is this some kind of default, forced error that happens due to there not being any URL provided/request performed?

Hello et.fz,

To execute an error in a request-less communication, you can use this code:

{
	"response": {
		"valid": {
			"condition": "{{parameters.assertion}}", //defines when the error should be thrown
			"message": "Uknown error.", //hardcoded message
			"type": "RuntimeError" //set error type
		},
		"output": "{{undefined}}"
	}
}

However, it is not possible to hardcode the code of the error, e.g. 400, 500. It is only possible to hardcode the error message and the type.

See the available error types here.

2 Likes

Works perfectly. Thank you!

{
	"response": {
		"valid": {
			"condition": "{{parameters.assertion}}",
			"message": "{{parameters.errorMessage}}",
			"type": "{{parameters.errorType}}"
		},
		"output": {"result": "{{parameters.assertion}}"}
	}
}
1 Like