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);
}
}
}
}
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;
}
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);
}
Aggregations