functionInvokeError function
Builds the right exception for a failed invocation.
A single type carrying a status number made every failure look alike: a missing Function, a caller without permission, and a Function that threw all arrived identically, and an application had to read the number to tell them apart. The distinction matters — one is a deployment problem, one is a permissions problem, and one is a bug in the Function.
Implementation
KoolbaseException functionInvokeError(int statusCode, String message) {
switch (statusCode) {
case 401:
// Not a Function failure. A rejected credential stops the whole SDK
// working, so it raises the shared type.
return KoolbaseUnauthenticatedException(message);
case 403:
return FunctionPermissionException(message);
case 404:
return FunctionNotFoundException(message);
case 400:
return FunctionValidationException(message);
case 402:
return FunctionQuotaExceededException(message);
}
if (statusCode >= 500) {
return FunctionExecutionException(message, statusCode: statusCode);
}
return FunctionInvokeException(message, statusCode: statusCode);
}