Skip to content

Commit

Permalink
Added "doesn't expose x-v: CORS" console message
Browse files Browse the repository at this point in the history
  • Loading branch information
vadkor committed Oct 4, 2023
1 parent 936f3e3 commit 6dae7e3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/components/data/ConsolePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ const ConsolePanel = (props) => {
{props.conout.actions.map((msg, i) =>
<div key={i}>
<span className={classes.timestamp}>{moment(msg.timestamp).format('L HH:mm:ss.SSS')}</span>
<span style={{color: msg.payload.lvl === 'error' ? 'red' : 'black'}}>{msg.payload.txt}</span>
{msg.payload.html
? <span style={{color: msg.payload.lvl === 'error' ? 'red' : 'black'}} dangerouslySetInnerHTML={{__html: msg.payload.html}}></span>
: <span style={{color: msg.payload.lvl === 'error' ? 'red' : 'black'}}>{msg.payload.txt}</span>
}
{msg.payload.obj && <TreeView data={msg.payload.obj}/>}
</div>
)}
Expand Down
10 changes: 9 additions & 1 deletion src/store/banking/data/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {conoutInfo, conoutError, conoutWarn} from '../../conout/actions'
import {conoutInfo, conoutError, conoutHtmlError, conoutWarn} from '../../conout/actions'
import {encodeRFC3986URIComponent} from '../../../utils/url'

export const START_RETRIEVE_PRODUCT_LIST = 'START_RETRIEVE_PRODUCT_LIST'
Expand Down Expand Up @@ -31,6 +31,14 @@ export const retrieveProductList = (dataSourceIdx, baseUrl, productListUrl, xV,
payload: fetch(request)
.then(response => {
if (response.ok) {
if (!response.headers['x-v']) {
const msg = `Response for ${productListUrl}: doesn't expose header x-v: possibly caused by incomplete `
const corsSupport = 'CORS support'
dispatch(conoutHtmlError(
msg + corsSupport,
`${msg}<a href="https://cdr-support.zendesk.com/hc/en-us/articles/900003054706-CORS-support" target="_blank">${corsSupport}</a>`
))
}
return response.json()
}
throw new Error(`Response not OK. Status: ${response.status} (${response.statusText})`)
Expand Down
4 changes: 4 additions & 0 deletions src/store/conout/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const conoutError = (txt, obj) => {
return createLogEntry({lvl: 'error', txt, obj})
}

export const conoutHtmlError = (txt, html, obj) => {
return createLogEntry({lvl: 'error', txt, html, obj})
}

function createLogEntry(payload) {
return {
type: CONSOLE_OUT,
Expand Down
10 changes: 9 additions & 1 deletion src/store/discovery/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {conoutInfo, conoutError} from '../conout/actions'
import {conoutInfo, conoutHtmlError, conoutError} from '../conout/actions'

export const RETRIEVE_STATUS = 'RETRIEVE_STATUS'
export const RETRIEVE_OUTAGES = 'RETRIEVE_OUTAGES'
Expand Down Expand Up @@ -48,6 +48,14 @@ export const retrieveOutages = (dataSourceIdx, url, xV, xMinV) => dispatch => {
payload: fetch(request)
.then(response => {
if (response.ok) {
if (!response.headers['x-v']) {
const msg = `Response for ${fullUrl}: doesn't expose header x-v: possibly caused by incomplete `
const corsSupport = 'CORS support'
dispatch(conoutHtmlError(
msg + corsSupport,
`${msg}<a href="https://cdr-support.zendesk.com/hc/en-us/articles/900003054706-CORS-support" target="_blank">${corsSupport}</a>`
))
}
return response.json()
}
throw new Error(`Response not OK. Status: ${response.status} (${response.statusText})`)
Expand Down
10 changes: 9 additions & 1 deletion src/store/energy/data/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {conoutInfo, conoutError} from '../../conout/actions'
import {conoutInfo, conoutHtmlError, conoutError} from '../../conout/actions'
import {encodeRFC3986URIComponent} from '../../../utils/url'

export const START_RETRIEVE_PLAN_LIST = 'START_RETRIEVE_PLAN_LIST'
Expand Down Expand Up @@ -30,6 +30,14 @@ export const retrievePlanList = (dataSourceIdx, baseUrl, planListUrl, xV, xMinV,
payload: fetch(request)
.then(response => {
if (response.ok) {
if (!response.headers['x-v']) {
const msg = `Response for ${planListUrl}: doesn't expose header x-v: possibly caused by incomplete `
const corsSupport = 'CORS support'
dispatch(conoutHtmlError(
msg + corsSupport,
`${msg}<a href="https://cdr-support.zendesk.com/hc/en-us/articles/900003054706-CORS-support" target="_blank">${corsSupport}</a>`
))
}
return response.json()
}
throw new Error(`Response not OK. Status: ${response.status} (${response.statusText})`)
Expand Down

0 comments on commit 6dae7e3

Please sign in to comment.