11![ image] ( https://github.com/INeedJobToStartWork/MyError/assets/97305201/03fa3e50-af28-4345-a3f7-f84d091b4eb1 )
22
33<h1 align =" center " >MyError</h1 >
4- <p align =" center " ><code >🎉2.0.0.prerelease.3 🎊</code ></p >
4+ <p align =" center " ><code >🎉2.0.0🎊</code ></p >
55<p align =" center " ><b >A Very Clean Error Handler!</b ></p >
66<div align =" center " >
77 <a href="https://github.com/INeedJobToStartWork/MyError/tree/main/tutorials/README.md">📗Tutorials</a> |
@@ -35,9 +35,9 @@ What you get:
3535// Instead
3636let data;
3737try {
38- data = readFile (" ...path" );
38+ data = readFile (" ...path" );
3939} catch {
40- throw Error (" Cant Load File!" );
40+ throw Error (" Cant Load File!" );
4141}
4242
4343// Do
@@ -116,11 +116,11 @@ Processes an error object, invoking functions with provided arguments
116116
117117``` ts
118118const MyErrorList = {
119- BLACKLISTED: {
120- name: " Black Listed Name" ,
121- hint: " Try use other one!" ,
122- message : (name : string ) => ` ${name } is on black list! ` ,
123- },
119+ BLACKLISTED: {
120+ name: " Black Listed Name" ,
121+ hint: " Try use other one!" ,
122+ message : (name : string ) => ` ${name } is on black list! `
123+ }
124124} as const satisfies TMyErrorList ;
125125
126126throw new myError (MyErrorList .BLACKLISTED , { message: [" nameInputed" ] });
@@ -164,10 +164,7 @@ const data = myErrorWrapper(readFile,err => new Error(`ERROR MESSAGE: ${err.mess
164164> At async function it returns Promise, just use ` await ` to solve that
165165
166166``` ts
167- const data = await myErrorWrapper (
168- asyncFun ,
169- new Error (" Oh, Error!" )
170- )(" MyString" );
167+ const data = await myErrorWrapper (asyncFun , new Error (" Oh, Error!" ))(" MyString" );
171168```
172169
173170### myErrorCatcher
@@ -176,8 +173,8 @@ const data = await myErrorWrapper(
176173
177174``` ts
178175const data = await myErrorCatcher (readFile )(" path..." ).catch (() => {
179- // Code before crash...
180- throw new Error (" Can't read file!" );
176+ // Code before crash...
177+ throw new Error (" Can't read file!" );
181178});
182179```
183180
@@ -189,10 +186,10 @@ Execute Scenarios for an error!
189186const [data, isError] = myErrorWrapper (readFile )(" ./ReadThisFile" );
190187
191188const MyErrorHandlerList = {
192- FS001 : () => {
193- // Do this code if throw this error
194- console .error (" ERROR" );
195- },
189+ FS001 : () => {
190+ // Do this code if throw this error
191+ console .error (" ERROR" );
192+ }
196193};
197194if (isError ) myErrorHandler (data .code , MyErrorHandlerList )();
198195```
@@ -211,24 +208,24 @@ if (isError) myErrorHandler(data.code, MyErrorHandlerList)();
211208
212209``` ts
213210const ErrorList = {
214- notFound: {
215- name: " Not Found" ,
216- code: " FS001" ,
217- message: {
218- user: " File not found" ,
219- dev: " The file you are trying to read does not exist" ,
220- },
221- hint : (path : string ) => ` Check if the file exists at ${path } ` ,
222- } satisfies IMyError ,
223- cantRead: {
224- code: " FS002" ,
225- name: " Cant Read" ,
226- message: { user: " Can't read file" , dev: " readFileSync throw error" },
227- hint: {
228- user: " Check if the file is not corrupted or permissions" ,
229- dev: " File is corrupted or has no permissions to be read" ,
230- },
231- },
211+ notFound: {
212+ name: " Not Found" ,
213+ code: " FS001" ,
214+ message: {
215+ user: " File not found" ,
216+ dev: " The file you are trying to read does not exist"
217+ },
218+ hint : (path : string ) => ` Check if the file exists at ${path } `
219+ } satisfies IMyError ,
220+ cantRead: {
221+ code: " FS002" ,
222+ name: " Cant Read" ,
223+ message: { user: " Can't read file" , dev: " readFileSync throw error" },
224+ hint: {
225+ user: " Check if the file is not corrupted or permissions" ,
226+ dev: " File is corrupted or has no permissions to be read"
227+ }
228+ }
232229} as const satisfies TMyErrorList ;
233230```
234231
0 commit comments