Skip to content

Commit

Permalink
Issue #173: More descriptive error message when creating/deploying an…
Browse files Browse the repository at this point in the history
…other users app

Signed-off-by: macdonst <[email protected]>
  • Loading branch information
macdonst committed Jan 12, 2024
1 parent affeac4 commit 4fde9a2
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 1 deletion.
43 changes: 43 additions & 0 deletions ack.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
let { readFileSync } = require('fs')
const $RefParser = require('@apidevtools/json-schema-ref-parser')
/*
function generateSchemaId(schemaId) {
let id = null
if (schemaId.startsWith('http')) {
let tmpUrl = new URL(schemaId)
id = tmpUrl.pathname
} else {
id = schemaId
}
return id.split('/').pop()
}

const schema = JSON.parse(readFileSync('./customer.schema.json'))

if (!schema.id && schema['$id']) {
schema.id = schema['$id']
}

const id = generateSchemaId(schema.id)

console.log(id)
console.log(generateSchemaId('/schemas/customer'))
console.log(generateSchemaId('person'))
*/

async function ack () {
const schema = JSON.parse(readFileSync('./game.schema.json'))
try {
let myschema = await $RefParser.dereference(schema)
console.log(JSON.stringify(myschema, null, 2))
}
catch (err) {
console.error(err)
}
}

ack()

// console.log(schema)


24 changes: 24 additions & 0 deletions commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// create

curl -X POST http://localhost:3333/accounts \
-H 'Content-Type: application/json' \
-d '{"email":"[email protected]","password":"my_password", "url": "https://begin.com", "tel": "1234"}'

// update

curl -X POST http://localhost:3333/accounts/pV4yAGkPfz \
-H 'Content-Type: application/json' \
-d '{"email":"[email protected]","password":"my_password", "url": "https://begin.com", "tel": "1234"}'

// delete

curl -X POST http://localhost:3333/accounts/pV4yAGkPfz/delete \
-H 'Content-Type: application/json'

// Insert your custom validation here
let accounts = await data.get({
table: 'accounts'
})
if (accounts.find(account => account.email === req.body.email)) {
problems.push('Email address already exists in database')
}
32 changes: 32 additions & 0 deletions game.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": "Game",
"$id": "Game",
"type": "object",
"required": [
"date", "time", "facility"
],
"properties": {
"date": {
"type": "string",
"format": "date"
},
"time": {
"type": "string",
"format": "time"
},
"facility": {
"type": "string"
},
"players": {
"type": "array",
"items": {
"$ref": "#/definitions/Player"
}
}
},
"definitions": {
"Player": {
"$ref": "player.schema.json"
}
}
}
33 changes: 33 additions & 0 deletions player.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"id": "Player",
"$id": "Player",
"type": "object",
"required": [
"name", "email", "position"
],
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"phone": {
"type": "string",
"format": "tel"
},
"position": {
"type": "string",
"enum": [
"Defence",
"Forward",
"Goalie",
"Skater"
]
},
"fulltime": {
"type": "boolean"
}
}
}
1 change: 1 addition & 0 deletions src/commands/create/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = async function action (params, utils) {
}
catch (err) {
if (err.message === 'app_not_found') return Error(`No app found with app ID '${appID}'`)
if (err.message === 'unknown_error') return Error(`No app found with app ID '${appID}' or the user does not have permission to access the app.`)
return
}
let envs = app.environments
Expand Down
9 changes: 8 additions & 1 deletion src/commands/deploy/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ module.exports = async function action (params, utils) {

// Go get the app (if we didn't just create one)
if (!app) {
app = await client.find({ token, appID, _staging })
try {
app = await client.find({ token, appID, _staging })
}
catch (err) {
if (err.message === 'app_not_found') return Error(`No app found with app ID '${appID}'`)
if (err.message === 'unknown_error') return Error(`No app found with app ID '${appID}' or the user does not have permission to access the app.`)
return
}
}

let envs = app.environments
Expand Down

0 comments on commit 4fde9a2

Please sign in to comment.