@concordiq/error-sdk 1.0.4 → 1.0.5
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 +1 -1
- package/readMe.md +151 -0
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -69,6 +69,157 @@ app.use(ErrorSDK.expressMiddleware());
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
✅ Default Import (Most Common)
|
|
73
|
+
import ErrorSDK from "@concordiq/error-sdk";
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
ErrorSDK.init({...});
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
✅ Named Import (Tree-shaking)
|
|
81
|
+
import { init, capture } from "@concordiq/error-sdk";
|
|
82
|
+
|
|
83
|
+
init({...});
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
✅ CommonJS
|
|
88
|
+
const ErrorSDK = require("@concordiq/error-sdk");
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
✅ Dynamic Import
|
|
93
|
+
const sdk = await import("@concordiq/error-sdk");
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
#
|
|
99
|
+
import express, {
|
|
100
|
+
Request,
|
|
101
|
+
Response,
|
|
102
|
+
NextFunction
|
|
103
|
+
} from "express";
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
import ErrorSDK from "@concordiq/error-sdk";
|
|
108
|
+
|
|
109
|
+
const app = express();
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Initialize once (on app startup)
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
ErrorSDK.init({
|
|
117
|
+
apiKey: "coiq-6ddfeede1d57a268f7131ef0597624200a8a02b7",
|
|
118
|
+
|
|
119
|
+
endpoint: "https://concordiq.onrender.com/api/v1/ingest/events",
|
|
120
|
+
|
|
121
|
+
env: "production",
|
|
122
|
+
|
|
123
|
+
service: "payment-api"
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Express error handler (optional custom)
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
export function expressHandler() {
|
|
133
|
+
return (
|
|
134
|
+
err: Error,
|
|
135
|
+
req: Request,
|
|
136
|
+
res: Response,
|
|
137
|
+
next: NextFunction
|
|
138
|
+
) => {
|
|
139
|
+
ErrorSDK.capture(err, {
|
|
140
|
+
url: req.originalUrl,
|
|
141
|
+
method: req.method,
|
|
142
|
+
user: (req as any).user?.id
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
next(err);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Register middleware (MUST be last)
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
app.use(ErrorSDK.expressMiddleware());
|
|
155
|
+
|
|
156
|
+
console.log("ErrorSDK loaded:", ErrorSDK);
|
|
157
|
+
#
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
`✅ Basic Usage in a Controller/Services (Recommended Way):`
|
|
162
|
+
``using this SDK inside controllers/services is actually the best practice, especially for business-logic errors.``
|
|
163
|
+
|
|
164
|
+
import { Request, Response, NextFunction } from "express";
|
|
165
|
+
import ErrorSDK from "@concordiq/error-sdk";
|
|
166
|
+
|
|
167
|
+
export const createPayment = async (
|
|
168
|
+
req: Request,
|
|
169
|
+
res: Response,
|
|
170
|
+
next: NextFunction
|
|
171
|
+
) => {
|
|
172
|
+
try {
|
|
173
|
+
// Your logic
|
|
174
|
+
const { amount } = req.body;
|
|
175
|
+
|
|
176
|
+
if (!amount) {
|
|
177
|
+
throw new Error("Amount is required");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Simulate error
|
|
181
|
+
if (amount < 100) {
|
|
182
|
+
throw new Error("Minimum payment is 100");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
res.status(201).json({
|
|
186
|
+
success: true,
|
|
187
|
+
message: "Payment created"
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
} catch (err) {
|
|
191
|
+
/**
|
|
192
|
+
* Capture error manually
|
|
193
|
+
*/
|
|
194
|
+
ErrorSDK.capture(err as Error, {
|
|
195
|
+
controller: "createPayment",
|
|
196
|
+
user: (req as any).user?.id,
|
|
197
|
+
body: req.body
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Pass to global handler
|
|
202
|
+
*/
|
|
203
|
+
next(err);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
`✅ Why This SDK Is Best for you:`
|
|
209
|
+
|
|
210
|
+
`This gives you:`
|
|
211
|
+
|
|
212
|
+
`✔ Controller name`
|
|
213
|
+
`✔ User info`
|
|
214
|
+
`✔ Request data`
|
|
215
|
+
`✔ Business context`
|
|
216
|
+
`✔ Stack trace`
|
|
217
|
+
`✔ Global error handling`
|
|
218
|
+
|
|
219
|
+
`Your dashboard becomes very useful.`
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
72
223
|
## Features:
|
|
73
224
|
|
|
74
225
|
1. Manual error tracking
|