| 1 | import { ProblemDetailsError } from "./ProblemDetailsError.js" |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | export function muestraError(error) { |
| 8 | |
| 9 | if (error instanceof ProblemDetailsError) { |
| 10 | |
| 11 | const problemDetails = error.problemDetails |
| 12 | |
| 13 | let mensaje = |
| 14 | typeof problemDetails["title"] === "string" ? problemDetails["title"] : "" |
| 15 | if (typeof problemDetails["detail"] === "string") { |
| 16 | if (mensaje !== "") { |
| 17 | mensaje += "\n" |
| 18 | } |
| 19 | mensaje += problemDetails["detail"] |
| 20 | } |
| 21 | if (mensaje === "") { |
| 22 | mensaje = "Error" |
| 23 | } |
| 24 | console.error(error, problemDetails) |
| 25 | alert(mensaje) |
| 26 | |
| 27 | } else if ( |
| 28 | typeof error === "object" && error !== null && "message" in error |
| 29 | ) { |
| 30 | |
| 31 | console.error(error) |
| 32 | alert(error.message) |
| 33 | |
| 34 | } else { |
| 35 | |
| 36 | console.error("Error", error) |
| 37 | alert("Error") |
| 38 | |
| 39 | } |
| 40 | |
| 41 | } |