private static BError generateError(Strand strand, boolean attachCallStack, BErrorType type, String reason, BMap<String, BValue> details) { BMap<String, BValue> detailMap = Optional.ofNullable(details).orElse(new BMap<>(BTypes.typeMap)); BError error = new BError(type, Optional.ofNullable(reason).orElse(""), detailMap); StructureTypeInfo typeInfo = getStructureTypeInfo(strand.programFile); if (attachCallStack) { attachStack(error, typeInfo, strand); } return error; }
void notifyErrorReply(Context context, String errorMessage) { BErrorType errType = BTypes.typeError; String reason = "{ballerina/grpc}" + INTERNAL.name(); BMap<String, BValue> refData = new BMap<>(errType.detailsType); refData.put("message", new BString(errorMessage)); context.setReturnValues(new BError(BTypes.typeError, reason, refData)); } }
private static BError getError(WebSocketOpenConnectionInfo connectionInfo, Throwable throwable) { String errMsg; if (isUnexpectedError(throwable)) { errMsg = "Unexpected internal error. Please check internal-log for more details!"; } else { errMsg = throwable.getMessage(); } Context context = connectionInfo.getContext(); if (context != null) { return HttpUtil.getError(context, errMsg); } else { ProgramFile programFile = connectionInfo.getService().getServiceInfo().getPackageInfo().getProgramFile(); BMap<String, BValue> httpErrorRecord = BLangConnectorSPIUtil.createBStruct( programFile, HttpConstants.PROTOCOL_PACKAGE_HTTP, HttpConstants.HTTP_ERROR_RECORD); httpErrorRecord.put(HttpConstants.HTTP_ERROR_MESSAGE, new BString(errMsg)); return new BError(BTypes.typeError, errMsg, httpErrorRecord); } }
return new BError(errorType, reason, refData);