function validateErrorResponse()

in packages/rulesets/src/spectral/functions/error-response.ts [138:162]


function validateErrorResponse(errorResponse:any, responsePath:any) {
  const errors = [];

  // The error response schema should conform to Microsoft API Guidelines
  if (!errorResponse.schema) {
    errors.push({
      message: 'Error response should have a schema.',
      path: responsePath,
    });
  } else {
    errors.push(
      ...validateErrorResponseSchema(errorResponse.schema, [...responsePath, 'schema']),
    );
  }

  // The error response should contain a x-ms-error-code header
  if (!errorResponse.headers || !errorResponse.headers['x-ms-error-code']) {
    errors.push({
      message: 'Error response should contain a x-ms-error-code header.',
      path: !errorResponse.headers ? responsePath : [...responsePath, 'headers'],
    });
  }

  return errors;
}