NoshonNetworks / landver

Onchain Land Management
https://landver.vercel.app/
MIT License
5 stars 20 forks source link

Create and Use a Custom Error Class in app/server #90

Open fishonamos opened 3 days ago

fishonamos commented 3 days ago

Description: Develop a custom error class to handle specific error scenarios within the app/server. This will provide more granular error handling and improve code readability.

Definition of Completion: A custom error class is created, extending the base Error class or a suitable error handling library. The class includes properties for error codes, messages, and potential additional data. The custom error class is used in relevant parts of the app/server to handle specific error conditions, and more informative error messages.

Note: Only applications through the OnlyDust platform will be considered.

abdegenius commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a fullstack developer worked with various frontend frameworks over the years as well as different backend languages. currently transitioning into the web3 space.

How I plan on tackling this issue

Can i be assigned this task!?

MullerTheScientist commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a full-stack developer with experience in QA testing and languages like Python, Cairo, Solidity, React, and JavaScript.

How I plan on tackling this issue

i will Use meaningful error codes and messages. Document custom error classes and codes. Consistently handle and log errors.

ikemHood commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hello @fishonamos, I would love to handle this

How I plan on tackling this issue

  1. First, i Will Create a new file errors.js in the middlewarefoled

  2. Then, Create the basic error class:

    class AppError extends Error {
    constructor(code, message, statusCode = 500) {
    super(message);
    this.code = code;
    this.statusCode = statusCode;
    }
    }
  3. Add a few specific error types:

    
    class ValidationError extends AppError {
    constructor(message) {
    super('VALIDATION_ERROR', message, 400);
    }
    }

class NotFoundError extends AppError { constructor(message) { super('NOT_FOUND', message, 404); } }


4. Add error handler middleware (if using Express):
```javascript
const errorHandler = (err, req, res, next) => {
  if (err instanceof AppError) {
    return res.status(err.statusCode).json({
      code: err.code,
      message: err.message
    });
  }
  return res.status(500).json({
    code: 'INTERNAL_ERROR',
    message: 'An unexpected error occurred'
  });
};
Mystic-Nayy commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a web3 developer, I have expertise in smart contracts, decentralized technologies, and frameworks like React. I can build innovative dApps, contribute to open-source projects, educate others, and network with industry leaders to advance my career in the decentralized space.

How I plan on tackling this issue

Create a custom error class that extends the base Error class, incorporating properties for error codes, messages, and any additional relevant data. Implement this custom error class in the app/server wherever specific error handling is needed, ensuring that informative error messages are generated. Test the implementation to verify that it provides granular error handling and improves code readability.

JosueBrenes commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, I'm Josué Brenes and I'll be working on issue. I'm Dojo Coding member.

I estimate this will take 3 day to complete.

How I plan on tackling this issue

Here’s how I would tackle this issue:

  1. Create a custom error class:

    • I will develop a new class that extends the native Error class in JavaScript or TypeScript. This custom error class will have additional properties for handling specific error codes, messages, and any other relevant data needed to provide more context in error scenarios.
    • I will define useful properties such as:
      • errorCode: A specific code that identifies the error type.
      • message: A detailed message to provide more information about the error.
      • details: Any additional data (like the failed request data, or user info) that might help with debugging.
  2. Integrate the custom error class within the app/server:

    • I will replace generic error handling in the relevant sections of the app/server with the new custom error class. This will ensure that the app responds with meaningful error messages and codes in different scenarios.
    • I will also add usage of this custom error class in key areas where the app handles specific error conditions (for example, failed API calls, validation errors, or database access issues).
  3. Improve error message readability:

    • I will ensure that the error messages are well-structured and readable, making it easier for developers to understand and fix issues.
    • I will also provide more granular information for different error scenarios so that it becomes easier to trace back the origin of the error in logs or monitoring tools.
  4. Test the custom error handling:

    • I will create unit tests to validate that the custom error class correctly captures and provides detailed information in various error scenarios.
    • I will also perform integration tests to verify that error handling across the app works as expected with the new custom error class.
  5. Completion Criteria:

    • The issue will be resolved when the custom error class is successfully created and integrated within the app/server.
    • The error handling system will be updated to provide more detailed and specific error messages in the relevant parts of the app.
    • Unit and integration tests will confirm the proper functionality of the custom error handling system.
JoelVR17 commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Create and Use a Custom Error Class in app/server

Hello LandVer team,

I am Joel Vargas, and I'm a member of Dojo Coding. I also come from OnlyDust.

I would like to request the assignment of this issue. Below is my proposed approach for implementing this issue:

How I plan on tackling this issue

Proposal to Develop a Custom Error Class for Improved Error Handling

Problem

Currently, the app/server may utilize generic error handling, which can lead to ambiguity and make it difficult to identify specific error scenarios. This lack of granularity can hinder debugging efforts and reduce code readability. A custom error class will allow us to handle errors more effectively and provide clearer feedback in various parts of the application.

Solution

To enhance error handling, I propose the development of a custom error class that extends the base Error class or utilizes a suitable error handling library. This custom error class will provide structured error information, improving the overall maintainability of the codebase.

Key Features

  1. Custom Error Class Implementation:

    • Create a custom error class that extends the standard JavaScript Error class.
    • Include properties such as errorCode, errorMessage, and additionalData to encapsulate relevant error information.
  2. Granular Error Handling:

    • Utilize the custom error class in relevant parts of the app/server to handle specific error conditions more effectively.
    • This will enable developers to catch and respond to different error scenarios with more precision.
  3. Informative Error Messages:

    • Ensure that the custom error class provides informative error messages that can assist in debugging.
    • Include stack traces and contextual information as needed to help identify the source of the error.

Implementation Details

  1. Custom Error Class Definition:

    • Create a new file (e.g., CustomError.js) to define the custom error class:

      class CustomError extends Error {
      constructor(errorCode, errorMessage, additionalData = null) {
       super(errorMessage);
       this.name = this.constructor.name;
       this.errorCode = errorCode;
       this.additionalData = additionalData;
       Error.captureStackTrace(this, this.constructor);
      }
      }
      
      export default CustomError;
  2. Using the Custom Error Class:

    • Replace existing error handling logic with the custom error class in relevant parts of the app/server. For example:

      import CustomError from './CustomError';
      
      function someFunction() {
      try {
       // Some operation that might fail
       throw new CustomError('USER_NOT_FOUND', 'The specified user does not exist', { userId: 123 });
      } catch (error) {
       if (error instanceof CustomError) {
         console.error(`Error Code: ${error.errorCode}, Message: ${error.message}`);
       } else {
         console.error('An unexpected error occurred:', error);
       }
      }
      }
  3. Testing and Validation:

    • After implementing the custom error class, conduct thorough testing to ensure it behaves as expected.
    • Create unit tests to validate that the custom error class can be instantiated correctly and provides the expected properties.

Definition of Completion

The project will be considered complete when:

Benefits

Next Steps

martinvibes commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

hello @ i'm an experienced frontend developer and a blockchain developer i would love to work on this issue Pleasee kindly assign :)

dimka90 commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

i am a cerfield full stack developer with half a decade years of experience in developing professional apps and webpages

How I plan on tackling this issue

I will approach the problem using this steps

  1. Create the Custom Error Class I would define a custom error class to handle specific error scenarios. It will include properties for error codes, messages, and additional data, improving error clarity.

2.Integrating the Custom Error Class in the Application In relevant parts of the app/server, I would use this custom error class to throw specific errors. For example, in routes or middleware, I would throw CustomError for cases like invalid input, unauthorized access, etc.

  1. Global Error Handler I would implement a global error handler to catch all errors and format the response appropriately. The handler would look for CustomError instances to display meaningful messages and status codes.

Testing and Usage Ensure the CustomError is used wherever errors are thrown in the app (e.g., API routes, services, etc.). Test the error handling with various scenarios, such as unauthorized access, invalid inputs, or other business logic failures. Confirm that meaningful messages and appropriate status codes are returned.

0xdevcollins commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, I'm Collins a frontend and blockchain developer, and an active contributor on OnlyDust. You can check out my profile here: https://app.onlydust.com/u/0xdevcollins. This is my first time contributing to this repository, and I’m excited about the opportunity to contribute. Looking forward to collaborating!

How I plan on tackling this issue

I'll develop a custom error class that extends the base Error class, adding properties like error codes and additional data for improved specificity. It will be implemented in relevant sections of the app/server to provide more detailed error messages, enhancing both error handling and code clarity.

od-hunter commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, please can I be assigned this please? This would be my first time contributing to this project and I would love to be the given the opportunity to contribute. I have experience in html, css, JavaScript,TypeScript and solidity, and Cairo.

How I plan on tackling this issue

To solve this issue, I’ll take the following steps:

  1. I’ll define a CustomError class extending the base Error class with properties for error codes, messages, status, and additional details.
  2. I’ll implement the custom error class in relevant areas of the application, throwing it when specific error conditions arise.
  3. I’ll update the documentation to explain the usage of the custom error class in my codebase.

Please assign me, I’m ready to work.

Dprof-in-tech commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hello, I'm Dprof-in-tech, a seasoned Full Stack Blockchain Developer, and I'm excited to be part of ODHACK 9! I have a strong foundation in technologies such as Next.js, TypeScript, JavaScript, React, Node.js, Rust, and Cairo, I've built extensive experience across the blockchain development landscape.

I first got involved with OnlyDust during Edition 2, and since then, I've made 39 contributions across 11 different projects. Working on the platform has really helped me sharpen my skills, especially when it comes to delivering great solutions under tight deadlines. I love combining technical know-how with a user-focused approach, whether it's building immersive 3D experiences or crafting smart contracts that solve real-world problems.

Throughout, I've consistently demonstrated the ability to adapt and contribute effectively to diverse challenges. I'm confident in my ability to tackle new problems and drive innovation within the blockchain space. As we kick off ODHACK 9, I'm eager to apply my previous experience and technical expertise to push the boundaries of what's possible.

You can view my public profile on OnlyDust here: https://app.onlydust.com/u/Dprof-in-tech

How I plan on tackling this issue

Approach for Issue #90: Create and Use a Custom Error Class in app/server

  1. Design the Custom Error Class: I’ll start by creating a custom error class that extends the native Error class in JavaScript. This class will allow us to define specific error properties like error codes, messages, and additional data. I’ll ensure that it accepts parameters for these properties so that we can throw more descriptive errors throughout the app.

This is a sample of what it could look like:

class CustomError extends Error { constructor(message, errorCode, data = null) { super(message); this.name = this.constructor.name; this.errorCode = errorCode; this.data = data; Error.captureStackTrace(this, this.constructor); } }

  1. Integrate the Custom Error Class: After defining the class, I’ll update relevant parts of the app/server to use it. This involves identifying key areas where specific error handling is needed, such as API calls, database operations, or external service requests. I’ll replace generic errors with instances of the custom error class, which will make debugging easier and provide more context to the errors.

This is a conceptual implementation of what it could look like. if (!user) { throw new CustomError("User not found", 404, { userId }); }

  1. Enhance Error Handling: I’ll ensure that all places where errors are caught (e.g., middleware, controllers) are updated to handle the new custom error class. This includes logging the error code and any additional data provided to the error class. For server responses, I’ll ensure the user sees clear, helpful error messages without exposing sensitive information.

  2. Testing and Validation: I’ll write test cases to validate that the custom error class works as expected. I’ll test both typical and edge cases to ensure the class captures errors correctly and that error messages are clear in various scenarios.

  3. Documentation and Best Practices: I’ll document the usage of the custom error class, outlining where and how to use it in the codebase. This will help ensure that future developers follow a consistent pattern for error handling, leading to better maintainability.

Expected time of delivery : 3-4 days

suhas-sensei commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

i have proper frontend experience, and looking forward to contribute to this repo

How I plan on tackling this issue

i would follow exactly what is mentioned and give you apt results.

Villarley commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am Santiago Villarreal Arley, a passionate software developer with a growing interest in Web3 technologies. Over the past few months, I've had the opportunity to work on innovative projects, such as BuildMyEvent, an open-source initiative that leverages blockchain and decentralized systems. I thrive on problem-solving and enjoy the challenge of integrating cutting-edge solutions into real-world applications. My goal is to contribute to the Web3 ecosystem by staying ahead of emerging trends, learning continuously, and developing projects that push the boundaries of decentralized technologies.

How I plan on tackling this issue

I would love to contribute to developing a custom error class for handling specific error scenarios within the app/server. Here’s my approach:

Class Creation:

I will create a custom error class that extends the base Error class or a suitable error handling library, depending on the current project setup. This will allow for more structured error management. Custom Properties:

The class will include additional properties such as errorCode, message, and possibly extra data like metadata or context, which can provide more detailed information about the error. Implementation in the App:

I will integrate the custom error class into the relevant parts of the app/server where specific error handling is required. This will allow for more precise error identification and messaging, which will enhance both debugging and user feedback. Error Handling Improvements:

By using this custom class, we can differentiate between different types of errors (e.g., validation errors, database errors) and improve the overall code readability and maintainability. It will also provide more informative error messages for both developers and users.

I’m excited to contribute to this feature and help improve the app's error handling capabilities!