Add SQLite support for easy setup (#336)

* Modifies schema to allow SQLite as a DB driver. SQLite is preinstalled in most OSes allowing for minimal prerequisites in the installation process.

* Removes Redis dependency and replaces "real" redis instance with ioredis-mock this is not feature complete and errors are expected.

* Updates medusa new command to only ask for Postgres credentials if the starter template has database_type === "postgres" in medusa-config.js

* Small improvements to bin resolution

* Improvements to endpoint stability
This commit is contained in:
Sebastian Rindom
2021-08-16 15:45:26 +02:00
committed by GitHub
parent 09d1b1a141
commit 1039d040e9
76 changed files with 2072 additions and 523 deletions
@@ -1,16 +1,39 @@
import { MedusaError } from "medusa-core-utils"
const QUERY_RUNNER_RELEASED = "QueryRunnerAlreadyReleasedError"
const TRANSACTION_STARTED = "TransactionAlreadyStartedError"
const TRANSACTION_NOT_STARTED = "TransactionNotStartedError"
const API_ERROR = "api_error"
const INVALID_REQUEST_ERROR = "invalid_request_error"
const INVALID_STATE_ERROR = "invalid_state_error"
export default () => {
return (err, req, res, next) => {
const logger = req.scope.resolve("logger")
logger.error(err.message)
logger.error(err)
console.error(err)
const errorType = err.type || err.name
const errObj = {
code: err.code,
type: err.type,
message: err.message,
}
let statusCode = 500
switch (err.name) {
case MedusaError.Types.DUPLICATE_ERROR:
switch (errorType) {
case QUERY_RUNNER_RELEASED:
case TRANSACTION_STARTED:
case TRANSACTION_NOT_STARTED:
statusCode = 409
errObj.code = INVALID_STATE_ERROR
errObj.message =
"The request conflicted with another request. You may retry the request with the provided Idempotency-Key."
break
case MedusaError.Types.DUPLICATE_ERROR:
statusCode = 402
errObj.code = INVALID_REQUEST_ERROR
break
case MedusaError.Types.NOT_ALLOWED:
case MedusaError.Types.INVALID_DATA:
@@ -21,14 +44,12 @@ export default () => {
break
case MedusaError.Types.DB_ERROR:
statusCode = 500
errObj.code = API_ERROR
break
default:
break
}
res.status(statusCode).json({
name: err.name,
message: err.message,
})
res.status(statusCode).json(errObj)
}
}