Skip to content

Commit 0e0653b

Browse files
committed
ADD: Manejo de errores
Se integra el manejo de errores issue #28
1 parent 075134a commit 0e0653b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/schemas/resolvers/BuildMutation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class BuildMutation {
2626
.then(data => this.modelo
2727
.query()
2828
.deleteById(...this.params)
29-
.then(() => data))
29+
.then((filas) => {
30+
if (filas > 0) return data;
31+
throw new Error(`El registro con el id ${this.params[0]} no se puede elmiar`);
32+
}))
3033
);
3134
}
3235

src/server.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ const PORT = 8080;
1414
SERVER.use(
1515
"/gql",
1616
BodyParser.json(),
17-
graphqlExpress({ schema: Schema }),
17+
graphqlExpress({
18+
schema: Schema,
19+
formatError: error => ({
20+
errorCode: "A55",
21+
name: error.name,
22+
mensaje: error.message,
23+
}),
24+
}),
1825
);
1926

2027
/**

0 commit comments

Comments
 (0)