Skip to content

Commit

Permalink
[SDPSUP] Fixed homepage error code (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-yao authored Nov 11, 2019
1 parent d82a502 commit d4b5990
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/ripple-nuxt-tide/lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,17 @@ export default async function (context, pageData) {
switch (context.app.tideResErrCode) {
case 404:
pageData.tideErrorType = '404'
if (typeof context.res !== 'undefined') {
context.res.statusCode = 404
}
break

default:
pageData.tideErrorType = 'other'
if (process.server) {
if (typeof context.res !== 'undefined') {
context.res.statusCode = 500
}
logger.error('Failed to get the page data.', { error })
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/ripple-nuxt-tide/lib/core/tide.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ export const tide = (axios, site, config) => ({
const entity = await this.get(endpoint, params, '', headersConfig)
return entity
} catch (error) {
// TODO: use return error instead of throw.
throw new Error(`Failed to get entity "${pathData.entity_type}/${pathData.bundle}/${pathData.uuid}" data, with error "${error}"`)
return new Error(`Failed to get entity "${pathData.entity_type}/${pathData.bundle}/${pathData.uuid}" data, with error "${error}"`)
}
},

Expand All @@ -385,8 +384,8 @@ export const tide = (axios, site, config) => ({
}

const entity = await this.getEntityByPathData(pathData, params, headersConfig)
if (!entity) {
throw new Error('Something wrong. Could not get any entity data from Tide based on API route response.')
if (entity instanceof Error) {
throw entity
}
pageData = jsonapiParse.parse(entity).data

Expand All @@ -408,6 +407,9 @@ export const tide = (axios, site, config) => ({
uuid: uuid
}
const entity = await this.getEntityByPathData(pathData, params, headersConfig)
if (entity instanceof Error) {
throw entity
}
const pageData = jsonapiParse.parse(entity).data

// Append the site section to page data
Expand Down
3 changes: 1 addition & 2 deletions packages/ripple-nuxt-tide/lib/templates/axios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@dpc-sdp/ripple-nuxt-tide/lib/core'

export default function ({ $axios, app }) {
export default function ({ $axios, app, res }) {

$axios.onRequest(config => {
// Log all axios' requests
Expand All @@ -20,7 +20,6 @@ export default function ({ $axios, app }) {

const responseUrl = error.request.path || error.request.responseURL || error.config.url


// Check what kind of request it is.
const routeRequest = responseUrl.includes('/route?')
const authPreviewRequest = responseUrl.includes('&current_version=') || responseUrl.includes('&resourceVersion=')
Expand Down

0 comments on commit d4b5990

Please sign in to comment.