fixup! fix(errors): properly output API error information

This commit is contained in:
Khaled Garbaya
2018-02-08 14:18:51 +01:00
committed by Khaled Garbaya
parent 9ee29c8555
commit fd6de6ef86
2 changed files with 14 additions and 3 deletions

10
app.js
View File

@@ -56,18 +56,22 @@ app.use(catchErrors(async function (request, response, next) {
const qs = querystring.stringify(request.query) const qs = querystring.stringify(request.query)
// Creates a query string which adds the current credentials to links // Creates a query string which adds the current credentials to links
// To other implementations of this app in the about modal // To other implementations of this app in the about modal
let settingsQs = null let settingsQuery = {
editorial_features: response.locals.settings.editorialFeatures ? 'enabled' : 'disabled'
}
if ( if (
response.locals.settings.spaceId !== process.env.CONTENTFUL_SPACE_ID || response.locals.settings.spaceId !== process.env.CONTENTFUL_SPACE_ID ||
response.locals.settings.deliveryToken !== process.env.CONTENTFUL_DELIVERY_TOKEN || response.locals.settings.deliveryToken !== process.env.CONTENTFUL_DELIVERY_TOKEN ||
response.locals.settings.previewToken !== process.env.CONTENTFUL_PREVIEW_TOKEN response.locals.settings.previewToken !== process.env.CONTENTFUL_PREVIEW_TOKEN
) { ) {
settingsQs = querystring.stringify(Object.assign({}, request.query, { settingsQuery = Object.assign({}, settingsQuery, request.query, {
space_id: response.locals.settings.spaceId, space_id: response.locals.settings.spaceId,
delivery_token: response.locals.settings.deliveryToken, delivery_token: response.locals.settings.deliveryToken,
preview_token: response.locals.settings.previewToken preview_token: response.locals.settings.previewToken
})) })
} }
const settingsQs = querystring.stringify(settingsQuery)
response.locals.queryString = qs ? `?${qs}` : '' response.locals.queryString = qs ? `?${qs}` : ''
response.locals.queryStringSettings = settingsQs ? `?${settingsQs}` : '' response.locals.queryStringSettings = settingsQs ? `?${settingsQs}` : ''
response.locals.query = request.query response.locals.query = request.query

View File

@@ -9,6 +9,8 @@ const { translate } = require('../i18n/i18n')
const { uniqWith, isEqual } = require('lodash') const { uniqWith, isEqual } = require('lodash')
const SETTINGS_NAME = 'theExampleAppSettings' const SETTINGS_NAME = 'theExampleAppSettings'
const querystring = require('querystring')
async function renderSettings (response, opts) { async function renderSettings (response, opts) {
// Get connected space to display the space name on top of the settings // Get connected space to display the space name on top of the settings
let space = false let space = false
@@ -162,6 +164,11 @@ module.exports.postSettings = async (request, response, next) => {
updateCookie(response, SETTINGS_NAME, settings) updateCookie(response, SETTINGS_NAME, settings)
response.locals.settings = settings response.locals.settings = settings
const settingsQuery = {
editorial_features: response.locals.settings.editorialFeatures ? 'enabled' : 'disabled'
}
const settingsQs = querystring.stringify(settingsQuery)
response.locals.queryStringSettings = settingsQs ? `?${settingsQs}` : ''
// Reinit clients // Reinit clients
initClients(settings) initClients(settings)
} }