Search in sources :

Example 1 with ServiceErrorSchemaArray

use of com.linkedin.restli.restspec.ServiceErrorSchemaArray in project rest.li by linkedin.

the class SnapshotGenerator method findErrorDetailTypeModels.

/**
 * For a given record that includes the {@link ServiceErrorsSchema} record, keep track of all referenced
 * error detail type models.
 *
 * @param schema record that includes the {@link ServiceErrorsSchema}
 * @param foundTypes running mapping of found data schemas
 * @param typeOrder running, ordered list of found data schemas
 */
private void findErrorDetailTypeModels(RecordTemplate schema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    // Wrap the underlying data map in the shared schema interface
    final ServiceErrorsSchema serviceErrorsSchema = new ServiceErrorsSchema(schema.data());
    // For each service error, inspect its error detail type field and keep track of all referenced types
    final ServiceErrorSchemaArray serviceErrorSchemaArray = serviceErrorsSchema.getServiceErrors();
    if (serviceErrorSchemaArray != null) {
        for (ServiceErrorSchema serviceErrorSchema : serviceErrorSchemaArray) {
            if (serviceErrorSchema.hasErrorDetailType()) {
                recordType(serviceErrorSchema.getErrorDetailType(), foundTypes, typeOrder);
            }
        }
    }
}
Also used : ServiceErrorsSchema(com.linkedin.restli.restspec.ServiceErrorsSchema) ServiceErrorSchema(com.linkedin.restli.restspec.ServiceErrorSchema) ServiceErrorSchemaArray(com.linkedin.restli.restspec.ServiceErrorSchemaArray)

Example 2 with ServiceErrorSchemaArray

use of com.linkedin.restli.restspec.ServiceErrorSchemaArray in project rest.li by linkedin.

the class ResourceModelEncoder method buildServiceErrors.

/**
 * Given a list of service errors, returns a service error schema array record.
 *
 * @param serviceErrors list of service errors to build, assumed to be non-null and non-empty
 * @return service error schema array
 */
private ServiceErrorSchemaArray buildServiceErrors(final List<ServiceError> serviceErrors) {
    final ServiceErrorSchemaArray serviceErrorSchemaArray = new ServiceErrorSchemaArray();
    // For each service error, build a service error schema and append it to the service error schema array
    for (ServiceError serviceError : serviceErrors) {
        ServiceErrorSchema serviceErrorSchema = new ServiceErrorSchema().setStatus(serviceError.httpStatus().getCode()).setCode(serviceError.code());
        final String message = serviceError.message();
        if (message != null) {
            serviceErrorSchema.setMessage(message);
        }
        final Class<?> errorDetailType = serviceError.errorDetailType();
        if (errorDetailType != null) {
            serviceErrorSchema.setErrorDetailType(errorDetailType.getCanonicalName());
        }
        if (serviceError instanceof ParametersServiceError) {
            final String[] parameterNames = ((ParametersServiceError) serviceError).parameterNames();
            if (parameterNames != null && parameterNames.length != 0) {
                serviceErrorSchema.setParameters(new StringArray(Arrays.asList(parameterNames)));
            }
        }
        serviceErrorSchemaArray.add(serviceErrorSchema);
    }
    return serviceErrorSchemaArray;
}
Also used : ParametersServiceError(com.linkedin.restli.server.errors.ParametersServiceError) ServiceError(com.linkedin.restli.server.errors.ServiceError) ParametersServiceError(com.linkedin.restli.server.errors.ParametersServiceError) StringArray(com.linkedin.data.template.StringArray) ServiceErrorSchema(com.linkedin.restli.restspec.ServiceErrorSchema) ServiceErrorSchemaArray(com.linkedin.restli.restspec.ServiceErrorSchemaArray)

Example 3 with ServiceErrorSchemaArray

use of com.linkedin.restli.restspec.ServiceErrorSchemaArray in project rest.li by linkedin.

the class ResourceModelEncoder method appendServiceErrors.

/**
 * Given a resource schema or resource method schema, adds the specified service errors.
 *
 * @param schema specific resource schema or a specific resource method schema
 * @param serviceErrors list of service errors to add to this schema
 */
private void appendServiceErrors(final RecordTemplate schema, final List<ServiceError> serviceErrors) {
    if (serviceErrors == null) {
        return;
    }
    // Wrap the underlying data map in the shared schema interface
    ServiceErrorsSchema serviceErrorsSchema = new ServiceErrorsSchema(schema.data());
    // Build the service error schema array
    ServiceErrorSchemaArray serviceErrorSchemas = buildServiceErrors(serviceErrors);
    serviceErrorsSchema.setServiceErrors(serviceErrorSchemas);
}
Also used : ServiceErrorsSchema(com.linkedin.restli.restspec.ServiceErrorsSchema) ServiceErrorSchemaArray(com.linkedin.restli.restspec.ServiceErrorSchemaArray)

Aggregations

ServiceErrorSchemaArray (com.linkedin.restli.restspec.ServiceErrorSchemaArray)3 ServiceErrorSchema (com.linkedin.restli.restspec.ServiceErrorSchema)2 ServiceErrorsSchema (com.linkedin.restli.restspec.ServiceErrorsSchema)2 StringArray (com.linkedin.data.template.StringArray)1 ParametersServiceError (com.linkedin.restli.server.errors.ParametersServiceError)1 ServiceError (com.linkedin.restli.server.errors.ServiceError)1