Validation Errors
Validation errors from Juniper Connect API will be returned in a consistent and predictable format. The HTTP 422 : Unprocessable Content status code is used exclusively to indicate the presence of validation errors.
Basic Example
{
"message": "The given data was invalid.",
"errors": {
"given_name": [
"Given name must be at least 2 characters long",
"Given name cannot contain numbers"
],
"email_address": [
"Email address must be a valid email address"
],
// Additional fields and their errors
}
}
message: This is a generic message indicating that the provided data was invalid.
errors: This is an object where each key represents a field that failed validation, and the corresponding value is an array of error messages for that field.
To the extent that is possible the Juniper Connect API will show user-friendly and context-specific error responses which can be displayed directly to the user.
Nested Fields & Dot Notation
For more complex objects with nested fields Juniper Connect supports dot notation:
{
"message": "The given data was invalid.",
"errors": {
"user.name": [
"The user name field is required."
],
"user.email": [
"The user email must be a valid email address."
],
"company.address.city": [
"The company address city field is required."
],
// Additional nested fields and their errors
}
}
Array validation
Juniper Connect also supports array validation. The following example shows how errors might be returned for issues in a list of people:
{
"message": "The given data was invalid.",
"errors": {
"people.0.name": [
"The name field for the first person is required."
],
"people.1.name": [
"The name field for the second person is required."
],
"people.1.email": [
"The email field for the second person must be a valid email address."
],
// Additional nested array of objects and their errors
}
}