feat: Typescript for API layer (#817)
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com> Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com> Co-authored-by: Sebastian Rindom <seb@medusa-commerce.com>
This commit is contained in:
co-authored by
Philip Korsholm
Zakaria El Asri
Kasper Fabricius Kristensen
Philip Korsholm
Sebastian Rindom
parent
55e200bf68
commit
373532ecbc
+12
-7
@@ -22,12 +22,21 @@ export const MedusaErrorCodes = {
|
||||
* @extends Error
|
||||
*/
|
||||
class MedusaError extends Error {
|
||||
public type: string
|
||||
public message: string
|
||||
public code?: string
|
||||
public date: Date
|
||||
public static Types = MedusaErrorTypes
|
||||
public static Codes = MedusaErrorCodes
|
||||
|
||||
/**
|
||||
* Creates a standardized error to be used across Medusa project.
|
||||
* @param type {MedusaErrorType} - the type of error.
|
||||
* @param params {Array} - Error params.
|
||||
* @param {string} type - type of error
|
||||
* @param {string} message - message to go along with error
|
||||
* @param {string} code - code of error
|
||||
* @param {Array} params - params
|
||||
*/
|
||||
constructor(type, message, code, ...params) {
|
||||
constructor(type: string, message: string, code?: string, ...params: any) {
|
||||
super(...params)
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
@@ -35,14 +44,10 @@ class MedusaError extends Error {
|
||||
}
|
||||
|
||||
this.type = type
|
||||
this.name = type
|
||||
this.code = code
|
||||
this.message = message
|
||||
this.date = new Date()
|
||||
}
|
||||
}
|
||||
|
||||
MedusaError.Types = MedusaErrorTypes
|
||||
MedusaError.Codes = MedusaErrorCodes
|
||||
|
||||
export default MedusaError
|
||||
@@ -1,11 +1,11 @@
|
||||
export { countries } from "./countries"
|
||||
export { isoCountryLookup } from "./countries"
|
||||
export { transformIdableFields } from "./transform-idable-fields"
|
||||
export { indexTypes } from "./index-types"
|
||||
export { default as Validator } from "./validator"
|
||||
export { default as compareObjectsByProp } from "./compare-objects"
|
||||
export { countries, isoCountryLookup } from "./countries"
|
||||
export { default as createRequireFromPath } from "./create-require-from-path"
|
||||
export { default as MedusaError } from "./errors"
|
||||
export { default as getConfigFile } from "./get-config-file"
|
||||
export { default as createRequireFromPath } from "./create-require-from-path"
|
||||
export { default as compareObjectsByProp } from "./compare-objects"
|
||||
export { default as zeroDecimalCurrencies } from "./zero-decimal-currencies"
|
||||
export { default as humanizeAmount } from "./humanize-amount"
|
||||
export { indexTypes } from "./index-types"
|
||||
export { transformIdableFields } from "./transform-idable-fields"
|
||||
export { default as Validator } from "./validator"
|
||||
export { default as zeroDecimalCurrencies } from "./zero-decimal-currencies"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user