Skip to content

Commit

Permalink
feat: If context is not found don't ask again
Browse files Browse the repository at this point in the history
  • Loading branch information
kosssi committed Dec 11, 2017
1 parent af6f03a commit 20e7e43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/BarStore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* global fetch */

import { Component } from 'react'
Expand Down Expand Up @@ -64,6 +63,7 @@ export default class BarStore {
}

fetchComingSoonApps () {
if (this.contextNoExist) return Promise.resolve(null)
return stack.get.context()
.then(context => {
const comingSoonApps = (context.data && context.data.attributes &&
Expand All @@ -89,6 +89,7 @@ export default class BarStore {
})
})
.catch(error => {
if (error.status && error.status === 404) this.contextNoExist = true
console.warn && console.warn(`Cozy-bar cannot fetch comming soon apps: ${error.message}`)
return []
})
Expand All @@ -109,6 +110,7 @@ export default class BarStore {
}

shouldEnableClaudy () {
if (this.contextNoExist) return Promise.resolve(null)
if (this.claudyActions) return Promise.resolve(this.claudyActions)
return stack.get.context()
.then(context => {
Expand All @@ -124,19 +126,22 @@ export default class BarStore {
return !!claudyActions.length
})
.catch(error => {
if (error.status && error.status === 404) this.contextNoExist = true
console.warn && console.warn(`Cozy-bar cannot fetch Claudy: ${error.message}`)
return false
})
}

getHelpLink () {
if (this.contextNoExist) return Promise.resolve(null)
if (this.helpLink) return Promise.resolve(this.helpLink)
return stack.get.context()
.then(context => {
this.helpLink = (context.data && context.data.attributes && context.data.attributes['help_link']) || null
return this.helpLink
})
.catch(e => {
if (error.status && error.status === 404) this.contextNoExist = true
console.warn && console.warn('Cannot get Cozy help link')
return null
})
Expand Down
5 changes: 5 additions & 0 deletions src/lib/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class ForbiddenException extends Error {
super()

this.name = 'Forbidden'
this.status = 403
this.message = message || 'The application does not have permission to access this resource.'
this.stack = (new Error()).stack
}
Expand All @@ -13,6 +14,7 @@ class ServerErrorException extends Error {
super()

this.name = 'ServerError'
this.status = 500
this.message = message || 'A server error occurred'
this.stack = (new Error()).stack
}
Expand All @@ -23,6 +25,7 @@ class NotFoundException extends Error {
super()

this.name = 'NotFound'
this.status = 404
this.message = message || 'The ressource was not found'
this.stack = (new Error()).stack
}
Expand All @@ -33,6 +36,7 @@ class MethodNotAllowedException extends Error {
super()

this.name = 'MethodNotAllowed'
this.status = 405
this.message = message || 'Method not allowed'
this.stack = (new Error()).stack
}
Expand All @@ -53,6 +57,7 @@ class UnauthorizedStackException extends Error {
super()

this.name = 'UnauthorizedStack'
this.status = 401
this.message = message || 'The app is not allowed to access to the requested resource'
this.stack = (new Error()).stack
}
Expand Down

0 comments on commit 20e7e43

Please sign in to comment.