flora-solr
Advanced tools
Comparing version 0.3.0 to 0.3.1
'use strict'; | ||
module.exports = function(grunt) { | ||
module.exports = function (grunt) { | ||
@@ -5,0 +5,0 @@ grunt.initConfig({ |
46
index.js
'use strict'; | ||
var http = require('http'), | ||
url = require('url'), | ||
_ = require('lodash'); | ||
var http = require('http'); | ||
var url = require('url'); | ||
var _ = require('lodash'); | ||
var errors = require('flora-errors'); | ||
var RequestError = errors.RequestError; | ||
var ImplementationError = errors.ImplementationError; | ||
/** | ||
@@ -45,5 +49,12 @@ * @constructor | ||
if (request.search) filters.push(escapeSpecialChars(request.search)); | ||
if (request.filter) filters.push(buildSolrFilterString(request.filter)); | ||
if (request.order) params.push('sort=' + encodeURIComponent(buildSolrOrderString(request.order))); | ||
if (request.filter) { | ||
try { | ||
filters.push(buildSolrFilterString(request.filter)); | ||
} catch (e) { | ||
return callback(e); | ||
} | ||
} | ||
if (filters.length) queryString = encodeURIComponent(filters.join(' AND ')); | ||
@@ -157,2 +168,6 @@ | ||
if (filter.operator === 'less' || filter.operator === 'greater') { | ||
throw new ImplementationError('DataSource "flora-solr" does not support "' + filter.operator + '" filters'); | ||
} | ||
if (! Array.isArray(filter.attribute)) { | ||
@@ -217,2 +232,10 @@ value = prepareValueForSolr(value); | ||
function parseData(str) { | ||
try { | ||
return JSON.parse(str); | ||
} catch (e) { | ||
return new Error('Couldn\'t parse response: ' + str); | ||
} | ||
} | ||
/** | ||
@@ -240,9 +263,16 @@ * | ||
if (res.statusCode >= 400) { | ||
error = new Error(http.STATUS_CODES[res.statusCode]); | ||
error.code = res.statusCode; | ||
data = parseData(str); | ||
if (res.statusCode >= 400 || data instanceof Error) { | ||
if (!(data instanceof Error)) { | ||
if (res.statusCode > 400) error = new Error(http.STATUS_CODES[res.statusCode]); | ||
else if (res.statusCode === 400) error = new RequestError(data.error.msg); | ||
error.code = res.statusCode; | ||
} else { | ||
error = data; | ||
error.code = 502; | ||
} | ||
return callback(error); | ||
} | ||
data = JSON.parse(str); | ||
callback(null, { totalCount: data.response.numFound, data: data.response.docs }); | ||
@@ -249,0 +279,0 @@ }); |
{ | ||
"name": "flora-solr", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Solr connection for Flora", | ||
@@ -38,20 +38,21 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "^3.10.1" | ||
"flora-errors": "^0.2.0", | ||
"lodash": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.3.0", | ||
"eslint": "^1.5.1", | ||
"chai": "^3.4.1", | ||
"eslint": "^1.10.3", | ||
"grunt": "^0.4.5", | ||
"grunt-cli": "^0.1.13", | ||
"grunt-contrib-clean": "^0.6.0", | ||
"grunt-eslint": "^17.2.0", | ||
"grunt-contrib-clean": "^0.7.0", | ||
"grunt-eslint": "^17.3.1", | ||
"grunt-mocha-istanbul": "^3.0.1", | ||
"grunt-mocha-test": "^0.12.7", | ||
"istanbul": "^0.3.21", | ||
"load-grunt-tasks": "^3.1.0", | ||
"mocha": "^2.3.3", | ||
"istanbul": "^0.4.2", | ||
"load-grunt-tasks": "^3.4.0", | ||
"mocha": "^2.3.4", | ||
"mocha-bamboo-reporter": "^1.1.0", | ||
"nock": "2.15.x", | ||
"when": "^3.7.3" | ||
"nock": "5.2.x", | ||
"when": "^3.7.7" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
13220
10
277
2
+ Addedflora-errors@^0.2.0
+ Addedflora-errors@0.2.0(transitive)
+ Addedlodash@4.17.21(transitive)
- Removedlodash@3.10.1(transitive)
Updatedlodash@^4.0.0