GithubHelp home page GithubHelp logo

Error handling about node-module-glpi HOT 6 OPEN

ajsb85 avatar ajsb85 commented on August 21, 2024
Error handling

from node-module-glpi.

Comments (6)

Gianfranco97 avatar Gianfranco97 commented on August 21, 2024 1

Sure. I'll check that

from node-module-glpi.

Gianfranco97 avatar Gianfranco97 commented on August 21, 2024 1

This issue is already resolved, it includes handling errors when returning a failed response that should be able to prevent this from happening again.

I already changed the way I handle the errors, I no longer make them an object and I split the error message in the semicolon as I was asked. Thus we see a message of a failed request in the library:

{ 
  status: 401,
  data: [ 
    'ERROR_GLPI_LOGIN', 
    'Incorrect username or password' 
  ]
}

I have not withdrawn the status of the object returned since although it is true that users could know if they are in the presence of an error without the presence of these, it is also true that there is always the possibility that to someone this fact is a useful one.

from node-module-glpi.

ajsb85 avatar ajsb85 commented on August 21, 2024

When the API does not return a JSON code I got a SyntaxError about the Unexpected token.
Instead print a proper error message in JSON file format.

node example-initSessionByCredentials.js
undefined:1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
^

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at _prepareRequest (/Users/<user>/GitHub/glpi/node-module-glpi/lib/restclient.js:78:31)
    at IncomingMessage.resp.on (/Users/<user>/GitHub/glpi/node-module-glpi/lib/restclient.js:59:5)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1059:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
<user>:example <user>$

from node-module-glpi.

ajsb85 avatar ajsb85 commented on August 21, 2024

In the method killSession, when no session token the promise is rejected with a text message: "Uninitialized session" (https://git.io/vFv2D) but for resolve you use the format in JSON.

An example for a message in the reject:

{
  status: 400,
  data: [
    'ERROR_SESSION_TOKEN_MISSING',
    '....'
  ]
}

Reference: https://git.io/vFv2o

from node-module-glpi.

ajsb85 avatar ajsb85 commented on August 21, 2024

Hi, @Gianfranco97

Could you split the error message in the semicolon to clean the error message?

Example:

missing parameter app_token; view documentation in your browser at https://dev.flyve.org/glpi/apirest.php/#ERROR_APP_TOKEN_PARAMETERS_MISSING

Output

missing parameter app_token

from node-module-glpi.

ajsb85 avatar ajsb85 commented on August 21, 2024

I think, is better to print only "data"
For "success" and "fails".

from node-module-glpi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.