Skip to content

Commit

Permalink
fix(core): bad error messages for certain error types
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jul 15, 2021
1 parent 925b291 commit 8500aec
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/src/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { omit } from "lodash"
import { isString, omit } from "lodash"

export interface GardenError {
type: string
Expand All @@ -25,15 +25,20 @@ export abstract class GardenBaseError extends Error implements GardenError {
}
}

export function toGardenError(err: Error | GardenBaseError | string): GardenBaseError {
export function toGardenError(err: Error | ErrorEvent | GardenBaseError | string): GardenBaseError {
if (err instanceof GardenBaseError) {
return err
} else if (err instanceof Error) {
const out = new RuntimeError(err.message, omit(err, ["message"]))
const out = new RuntimeError(err.message, err)
out.stack = err.stack
return out
} else {
} else if (err instanceof ErrorEvent) {
return new RuntimeError(err.message, err)
} else if (isString(err)) {
return new RuntimeError(err, {})
} else {
const msg = err["message"]
return new RuntimeError(msg, err)
}
}

Expand Down

0 comments on commit 8500aec

Please sign in to comment.