|
1
|
export type PanicData = { |
|
2
|
id: string |
|
3
|
context: { |
|
4
|
rootPath: string |
|
5
|
path: string |
|
6
|
} |
|
7
|
} |
|
8
|
|
|
9
|
export enum PanicId { |
|
10
|
InvalidProjectName = "10000", |
|
11
|
InvalidPath = "10002", |
|
12
|
AlreadyNodeProject = "10003", |
|
13
|
} |
|
14
|
|
|
15
|
export const panicHandler = (panicData: PanicData = {} as PanicData) => { |
|
16
|
const { id, context } = panicData |
|
17
|
switch (id) { |
|
18
|
case "10000": |
|
19
|
return { |
|
20
|
message: `Looks like you provided a URL as your project name. Try "medusa new my-medusa-store ${context.rootPath}" instead.`, |
|
21
|
} |
|
22
|
case "10002": |
|
23
|
return { |
|
24
|
message: `Could not create project because ${context.path} is not a valid path.`, |
|
25
|
} |
|
26
|
case "10003": |
|
27
|
return { |
|
28
|
message: `Directory ${context.rootPath} is already a Node project.`, |
|
29
|
} |
|
30
|
default: |
|
31
|
return { |
|
32
|
message: "Unknown error", |
|
33
|
} |
|
34
|
} |
|
35
|
} |