cordo 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordo",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "A framework for handling complex discord api interactions",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -1,4 +1,3 @@
1
- import { CordoError } from "../../errors"
2
1
  import type { RouteRequest } from "./route"
3
2
 
4
3
 
@@ -9,7 +8,7 @@ export type CordoErrorBoundary = {
9
8
  handler: CordoErrorHandler
10
9
  }
11
10
 
12
- export type CordoErrorHandler = (error: CordoError, request: RouteRequest) => any
11
+ export type CordoErrorHandler = (error: Error, request: RouteRequest) => any
13
12
 
14
13
  export function defineCordoErrorBoundary(handler: CordoErrorHandler): CordoErrorBoundary {
15
14
  return {
@@ -90,8 +90,10 @@ export namespace RoutingRespond {
90
90
  if (!options)
91
91
  return {}
92
92
 
93
- if (options.length === 1 && options[0].type === ApplicationCommandOptionType.SubcommandGroup)
94
- return parseCommandOptions(options[0].options)
93
+ if (options.length === 1) {
94
+ if (options[0].type === ApplicationCommandOptionType.Subcommand || options[0].type === ApplicationCommandOptionType.SubcommandGroup)
95
+ return parseCommandOptions(options[0].options)
96
+ }
95
97
 
96
98
  return (options as Record<string, any>[]).reduce((out, opt) => ({ [opt.name]: opt.value, ...out }), {})
97
99
  }
@@ -42,11 +42,14 @@ export namespace HandleErrors {
42
42
  .sort((a, b) => b.specificity - a.specificity)
43
43
  }
44
44
 
45
- function useDefaultHandler(error: CordoError) {
46
- console.trace('No error handler found for', error.name)
45
+ function useDefaultHandler(error: Error) {
46
+ if (error instanceof CordoError)
47
+ console.trace('No error handler found for', error.name)
48
+ else
49
+ console.error(error)
47
50
  }
48
51
 
49
- async function handleErrorStack(initialError: CordoError, handlers: CordoErrorHandler[], request: RouteRequest) {
52
+ async function handleErrorStack(initialError: Error, handlers: CordoErrorHandler[], request: RouteRequest) {
50
53
  const handler = handlers.shift()
51
54
  if (!handler)
52
55
  return useDefaultHandler(initialError)
@@ -54,10 +57,8 @@ export namespace HandleErrors {
54
57
  try {
55
58
  await handler(initialError, request)
56
59
  } catch (error) {
57
- if (error instanceof CordoError)
60
+ if (error instanceof Error)
58
61
  handleErrorStack(error, handlers, request)
59
- else
60
- handleNonCordoError(error)
61
62
  }
62
63
  }
63
64
 
@@ -68,9 +69,4 @@ export namespace HandleErrors {
68
69
  handleErrorStack(error, boundaries.map(b => b.impl.handler), request)
69
70
  }
70
71
 
71
- export function handleNonCordoError(error: any) {
72
- console.error('(dev) Non cordo error:')
73
- console.error(error)
74
- }
75
-
76
72
  }