Skip to content
This repository has been archived by the owner on Jan 7, 2018. It is now read-only.

Commit

Permalink
Fix for the legacy camel case variables not working the same.
Browse files Browse the repository at this point in the history
Due to the order in which these were being looped over, if these
variables contained other internal variables, the legacy copies weren't
working properly (since they were bein modified later).
  • Loading branch information
GUI committed Sep 18, 2015
1 parent 6d2e657 commit f5926a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/gatekeeper/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var _ = require('lodash'),
Negotiator = require('negotiator'),
url = require('url');

exports.errorHandler = function(request, response, error, data) {
exports.errorHandler = function(request, response, error, errorSpecificData) {
var availableMediaTypes = ['application/json', 'application/xml', 'text/csv', 'text/html'];

// Prefer the format from the extension given in the URL.
Expand Down Expand Up @@ -57,9 +57,9 @@ exports.errorHandler = function(request, response, error, data) {
logger.error({ error_type: error }, 'Error data not found for error type: ' + error);
}

data = _.merge({
var data = _.merge({
base_url: request.base,
}, data || {}, commonErrorData, errorData);
}, commonErrorData);

// Support legacy camel-case capitalization of variables. Moving forward,
// we're trying to clean things up and standardize on snake-case.
Expand All @@ -73,6 +73,8 @@ exports.errorHandler = function(request, response, error, data) {
data.contactUrl = data.contact_url;
}

data = _.merge(data, errorSpecificData || {}, errorData);

var prop;
for(prop in data) {
try {
Expand Down
12 changes: 11 additions & 1 deletion test/server/formatted_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('formatted error responses', function() {
error_data: {
api_key_missing: {
embedded: 'base_url: {{base_url}} signup_url: {{signup_url}} contact_url: {{contact_url}}',
embedded_legacy: 'baseUrl: {{baseUrl}} signupUrl: {{signupUrl}} contactUrl: {{contactUrl}}',
},
},
error_templates: {
Expand All @@ -124,7 +125,8 @@ describe('formatted error responses', function() {
'"signupUrl": {{signupUrl}},' +
'"contact_url": {{contact_url}},' +
'"contactUrl": {{contactUrl}},' +
'"embedded": {{embedded}} ' +
'"embedded": {{embedded}},' +
'"embedded_legacy": {{embedded_legacy}} ' +
'}',
},
},
Expand Down Expand Up @@ -187,6 +189,14 @@ describe('formatted error responses', function() {
done();
});
});

it('substitutes legacy camel case variables embedded inside of other variables', function(done) {
request.get('http://localhost:9333/embedded_legacy.json', function(error, response, body) {
var data = JSON.parse(body);
data.embedded_legacy.should.eql('baseUrl: http://localhost:9333 signupUrl: http://localhost:9333 contactUrl: http://localhost:9333/contact/');
done();
});
});
});

describe('format validation', function() {
Expand Down

0 comments on commit f5926a8

Please sign in to comment.