Skip to content

CURL and REST via Fetch (JavaScript/NodeJs) have different results when trying to create a type that already exists #1463

Closed

Description

@apttap

ArcadeDB Version:

ArcadeDB Server v24.1.1 (build 48e937e9a860ea97a7f245994a9df8bdb6af56d2/1707162918298/main)

OS and JDK Version:

Linux 6.2.0-33-generic - OpenJDK 64-Bit Server VM 17.0.9

Expected behavior

That it is consistent with the API via curl.

Actual behavior

Trying to create a type that already exists in JavaScript (fetch, NodeJS) yields a 500 error, while curl returns a JSON object explaining the problem.

Steps to reproduce

const result = await fetch('http://localhost:2480/api/v1/command/Test', {
    method: 'POST',
    headers: {
      'Authorization': `Basic ${Buffer.from('root:password').toString('base64')}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"language":"sql","command":"CREATE document TYPE TestType BUCKET TestBucket"}),
  });
  console.log(result.status);
  // 500
  console.log(await result.json());
  // undefined 

while a curl with the same parameters returns a response (either it already exists, or success)

curl -X POST http://localhost:2480/api/v1/command/Test \
     -d '{"language":"sql","command":"CREATE document TYPE TestType BUCKET TestBucket"}' \
     -H "Content-Type: application/json" \
     --user root:password
## {"error":"Cannot execute command","detail":"Type TestType already exists","exception":"com.arcadedb.exception.CommandExecutionException"}

Activity

  1. changed the title [-]CURL and Rest via JS Fetch have different results when trying to create a type that already exists[/-] [+]CURL and REST via Fetch (JavaScript/NodeJs) have different results when trying to create a type that already exists[/+] on Feb 14, 2024
  2. lvca commented on Feb 14, 2024

    @lvca
    Member

    I think the JSON is in the error response. Try to call curl with -v option to see the error code returned. It should be 500.

  3. apttap commented on Feb 14, 2024

    @apttap
    Author

    It should be 500.

    You're right. Then I tried it with axios, and it returns a data object matching the CURL request.

    It's returning what I would expect with the following, so there must be some problem in my code elsewhere.

      fetch('http://localhost:2480/api/v1/command/Test', {
        method: 'POST',
        headers: {
          'Authorization': `Basic ${Buffer.from('root:password').toString('base64')}`,
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          language: 'sql',
          command: 'CREATE document TYPE Test BUCKET TestBucket',
        }),
      })
        .then(async (response) => {
          if (!response.ok) {
            console.log('error: ', await response.json());
          }
        })

    I'm handling these errors in my library & throwing them as JS errors, perhaps that is the issue. I'll need to refactor how I was handling 500 errors. Thank you, closing

  4. self-assigned this
    on Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions