Skip to content

Commit 2c3197d

Browse files
authored
Merge pull request #604 from idurar/dev
🥅 Imrpove Error Catch
2 parents 34fb7e6 + 4d7d248 commit 2c3197d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+278
-367
lines changed

backend/controllers/appControllers/clientController/remove.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ const remove = async (req, res) => {
4848
result,
4949
message: 'Successfully Deleted the client by id: ' + id,
5050
});
51-
} catch (err) {
51+
} catch (error) {
5252
return res.status(500).json({
5353
success: false,
5454
result: null,
55-
message: 'Oops there is an Error',
56-
error: err,
55+
message: error.message,
56+
error: error,
5757
});
5858
}
5959
};

backend/controllers/appControllers/invoiceController/create.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ const create = async (req, res) => {
7171
result: updateResult,
7272
message: 'Invoice created successfully',
7373
});
74-
} catch (err) {
75-
console.log(err);
76-
// If err is thrown by Mongoose due to required validations
77-
if (err.name == 'ValidationError') {
74+
} catch (error) {
75+
console.log(error);
76+
// If error is thrown by Mongoose due to required validations
77+
if (error.name == 'ValidationError') {
7878
return res.status(400).json({
7979
success: false,
8080
result: null,
81-
error: err,
81+
error: error,
8282
message: 'Required fields are not supplied',
8383
});
8484
} else {
8585
// Server Error
8686
return res.status(500).json({
8787
success: false,
8888
result: null,
89-
error: err,
90-
message: 'Oops there is an Error',
89+
error: error,
90+
message: error.message,
9191
});
9292
}
9393
}

backend/controllers/appControllers/invoiceController/mailInvoiceController.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,38 @@ const sendMail = async (req, res) => {
5252
}
5353
}
5454
)
55-
.catch((err) => {
55+
.catch((error) => {
5656
return res.status(500).json({
5757
success: false,
5858
result: null,
59-
error: err,
60-
message: 'Oops there is an Error',
59+
error: error,
60+
message: error.message,
6161
});
6262
});
63-
} catch (err) {
64-
// If err is thrown by Mongoose due to required validations
65-
if (err.name == 'ValidationError') {
63+
} catch (error) {
64+
// If error is thrown by Mongoose due to required validations
65+
if (error.name == 'ValidationError') {
6666
return res.status(400).json({
6767
success: false,
6868
result: null,
69-
error: err,
69+
error: error,
7070
message: 'Required fields are not supplied',
7171
});
72-
} else if (err.name == 'BSONTypeError') {
73-
// If err is thrown by Mongoose due to invalid ID
72+
} else if (error.name == 'BSONTypeError') {
73+
// If error is thrown by Mongoose due to invalid ID
7474
return res.status(400).json({
7575
success: false,
7676
result: null,
77-
error: err,
77+
error: error,
7878
message: 'Invalid ID',
7979
});
8080
} else {
8181
// Server Error
8282
return res.status(500).json({
8383
success: false,
8484
result: null,
85-
error: err,
86-
message: 'Oops there is an Error',
85+
error: error,
86+
message: error.message,
8787
});
8888
}
8989
}

backend/controllers/appControllers/invoiceController/remove.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ const remove = async (req, res) => {
3333
result: deletedInvoice,
3434
message: 'Invoice deleted successfully',
3535
});
36-
} catch (err) {
36+
} catch (error) {
3737
return res.status(500).json({
3838
success: false,
3939
result: null,
40-
error: err,
41-
message: 'Oops there is an Error',
40+
error: error,
41+
message: error.message,
4242
});
4343
}
4444
};

backend/controllers/appControllers/invoiceController/summary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ const summary = async (req, res) => {
203203
return res.status(500).json({
204204
success: false,
205205
result: null,
206-
message: 'Oops there is an Error',
206+
message: error.message,
207207
error: error,
208208
});
209209
}

backend/controllers/appControllers/invoiceController/update.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ const update = async (req, res) => {
7777
result,
7878
message: 'we update this document by this id: ' + req.params.id,
7979
});
80-
} catch (err) {
81-
// If err is thrown by Mongoose due to required validations
82-
if (err.name == 'ValidationError') {
80+
} catch (error) {
81+
// If error is thrown by Mongoose due to required validations
82+
if (error.name == 'ValidationError') {
8383
return res.status(400).json({
8484
success: false,
8585
result: null,
86-
error: err,
86+
error: error,
8787
message: 'Required fields are not supplied',
8888
});
8989
} else {
9090
// Server Error
9191
return res.status(500).json({
9292
success: false,
9393
result: null,
94-
error: err,
95-
message: 'Oops there is an Error',
94+
error: error,
95+
message: error.message,
9696
});
9797
}
9898
}

backend/controllers/appControllers/offerController/create.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ const create = async (req, res) => {
5757
result: updateResult,
5858
message: 'Offer created successfully',
5959
});
60-
} catch (err) {
61-
// If err is thrown by Mongoose due to required validations
62-
if (err.name == 'ValidationError') {
60+
} catch (error) {
61+
// If error is thrown by Mongoose due to required validations
62+
if (error.name == 'ValidationError') {
6363
return res.status(400).json({
6464
success: false,
6565
result: null,
@@ -70,7 +70,7 @@ const create = async (req, res) => {
7070
return res.status(500).json({
7171
success: false,
7272
result: null,
73-
message: err.message,
73+
message: error.message,
7474
});
7575
}
7676
}

backend/controllers/appControllers/offerController/summary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const summary = async (req, res) => {
110110
return res.status(500).json({
111111
success: false,
112112
result: null,
113-
message: 'Oops there is an Error',
113+
message: error.message,
114114
error: error,
115115
});
116116
}

backend/controllers/appControllers/offerController/update.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ const update = async (req, res) => {
5555
result,
5656
message: 'we update this document by this id: ' + req.params.id,
5757
});
58-
} catch (err) {
59-
// If err is thrown by Mongoose due to required validations
60-
console.log(err);
61-
if (err.name == 'ValidationError') {
58+
} catch (error) {
59+
// If error is thrown by Mongoose due to required validations
60+
console.log(error);
61+
if (error.name == 'ValidationError') {
6262
return res.status(400).json({
6363
success: false,
6464
result: null,
@@ -69,7 +69,7 @@ const update = async (req, res) => {
6969
return res.status(500).json({
7070
success: false,
7171
result: null,
72-
message: 'Oops there is an Error',
72+
message: error.message,
7373
});
7474
}
7575
}

backend/controllers/appControllers/paymentController/create.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ const create = async (req, res) => {
8080
result: updatePath,
8181
message: 'Payment Invoice created successfully',
8282
});
83-
} catch (err) {
84-
// If err is thrown by Mongoose due to required validations
85-
if (err.name == 'ValidationError') {
83+
} catch (error) {
84+
// If error is thrown by Mongoose due to required validations
85+
if (error.name == 'ValidationError') {
8686
res.status(400).json({
8787
success: false,
8888
result: null,
8989
message: 'Required fields are not supplied',
90-
error: err,
90+
error: error,
9191
});
9292
} else {
9393
// Server Error
9494
res.status(500).json({
9595
success: false,
9696
result: null,
97-
message: 'Oops there is an Error',
98-
error: err,
97+
message: error.message,
98+
error: error,
9999
});
100100
}
101101
}

backend/controllers/appControllers/paymentController/remove.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ const remove = async (req, res) => {
6464
result,
6565
message: 'Successfully Deleted the document by id: ' + req.params.id,
6666
});
67-
} catch (err) {
67+
} catch (error) {
6868
return res.status(500).json({
6969
success: false,
7070
result: null,
71-
message: 'Oops there is an Error',
72-
error: err,
71+
message: error.message,
72+
error: error,
7373
});
7474
}
7575
};

backend/controllers/appControllers/paymentController/summary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const summary = async (req, res) => {
6666
return res.status(500).json({
6767
success: false,
6868
result: null,
69-
message: 'Oops there is an Error',
69+
message: error.message,
7070
error: error,
7171
});
7272
}

backend/controllers/appControllers/paymentController/update.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,22 @@ const update = async (req, res) => {
8484
result,
8585
message: 'Successfully updated the Payment ',
8686
});
87-
} catch (err) {
88-
// If err is thrown by Mongoose due to required validations
89-
if (err.name == 'ValidationError') {
87+
} catch (error) {
88+
// If error is thrown by Mongoose due to required validations
89+
if (error.name == 'ValidationError') {
9090
res.status(400).json({
9191
success: false,
9292
result: null,
9393
message: 'Required fields are not supplied',
94-
error: err,
94+
error: error,
9595
});
9696
} else {
9797
// Server Error
9898
res.status(500).json({
9999
success: false,
100100
result: null,
101-
message: err.message,
102-
error: err,
101+
message: error.message,
102+
error: error,
103103
});
104104
}
105105
}

backend/controllers/appControllers/quoteController/convertQuoteToInvoice.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ const convertQuoteToInvoice = async (req, res) => {
5050
note: quote.note,
5151
};
5252

53+
invoiceData['createdBy'] = req.admin._id;
54+
// Creating a new document in the collection
55+
5356
// Create the invoice document
5457
const invoice = await new InvoiceModel(invoiceData).save();
5558

5659
// Mark the quote as converted
60+
quote['createdBy'] = req.admin._id;
5761
quote.converted = true;
5862
await quote.save();
5963

@@ -63,19 +67,21 @@ const convertQuoteToInvoice = async (req, res) => {
6367
result: quote,
6468
message: 'Successfully converted quote to invoice',
6569
});
66-
} catch (err) {
70+
} catch (error) {
6771
// If error is because of Invalid ObjectId
68-
if (err.kind == 'ObjectId') {
72+
if (error.kind == 'ObjectId') {
6973
return res.status(400).json({
7074
success: false,
7175
result: null,
7276
message: 'Invalid ID format',
77+
error: error,
7378
});
7479
} else {
7580
return res.status(500).json({
7681
success: false,
7782
result: null,
78-
message: 'Oops there is an Errorr',
83+
error,
84+
message: error.message,
7985
});
8086
}
8187
}

backend/controllers/appControllers/quoteController/create.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ const create = async (req, res) => {
5656
result: updateResult,
5757
message: 'Quote created successfully',
5858
});
59-
} catch (err) {
60-
// If err is thrown by Mongoose due to required validations
61-
if (err.name == 'ValidationError') {
59+
} catch (error) {
60+
// If error is thrown by Mongoose due to required validations
61+
if (error.name == 'ValidationError') {
6262
return res.status(400).json({
6363
success: false,
6464
result: null,
@@ -69,7 +69,7 @@ const create = async (req, res) => {
6969
return res.status(500).json({
7070
success: false,
7171
result: null,
72-
message: 'Oops there is an Error',
72+
message: error.message,
7373
});
7474
}
7575
}

0 commit comments

Comments
 (0)