cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

adding custom error messages in custom sdk

kavindu21
Deputy Chef I
Deputy Chef I

How to add validations for the fields here and display error messages when the fields are empty? 

connection: {

  fields: [
    {
      name: "username",
      hint: "Your email used for login"
    },
    {
      name: "password",
      optional: false,
      control_type: "password",
    }
  ],

  authorization: {
    type: "basic_auth",

    credentials: lambda do |connection|
      user(connection["username"])
      password(connection["password"])
    end
  }
}
2 REPLIES 2

julie-reyes
Workato employee
Workato employee

Hi,

After reviewing your case, I suggest making the two fields required instead of validating the input upon trying to connect. This will ensure that the connector does not allow the user to connect if the fields are left empty. By making them required, the connector will automatically throw an error when it detects empty values, prompting the user to fill in the necessary information.

I hope this solution will help resolve the issue you are experiencing. If you have any further questions or concerns, please do not hesitate to reach out to us. We are always happy to assist you.

Thank you

 

timwolfe
Deputy Chef I
Deputy Chef I

To add validations for the fields in your connection configuration and display error messages when the fields are empty, you can incorporate conditional logic that checks for the presence of these fields before proceeding with the connection. Below is an example of how to implement this:

connection: {
fields: [
{
name: "username",
hint: "Your email used for login",
optional: false
},
{
name: "password",
optional: false,
control_type: "password"
}
],

authorization: {
type: "basic_auth",

credentials: lambda do |connection|
if connection["username"].blank? || connection["password"].blank?
raise "Username and password cannot be empty."
end

user(connection["username"])
password(connection["password"])
end
}
}