Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@unkey/api 0.26.2] response.error.message is undefined despite valid error object #2387

Closed
3 tasks done
unrenamed opened this issue Oct 13, 2024 · 8 comments
Closed
3 tasks done
Assignees
Labels
Bug Something isn't working Core Team

Comments

@unrenamed
Copy link
Contributor

unrenamed commented Oct 13, 2024

Preliminary Checks

Reproduction / Replay Link (Optional)

No response

Issue Summary

When calling the @unkey/api methods (e.g. unkey.keys.create), the response.error.message field is undefined, because of the nested error object though the response.error object exists and contains other fields such as code and docs.

{
  error: {
    error: {
      code: 'BAD_REQUEST',
      docs: 'https://unkey.dev/docs/api-reference/errors/code/BAD_REQUEST',
      message: 'remaining must be set if you are using refill.',
      requestId: 'req_*************'
    }
  }
}

When the expected response format contains one error object in the response:

{
  error: {
    // A machine readable error code
    code: ErrorCode;

    // A link to our documentation explaining this error in more detail
    docs: string;

    // A human readable short explanation
    message: string;

    // The request id for easy support lookup
    requestId: string;
  }
}

Same for verifyKey method. So I assume this may be a general behaviour for all methods.

Steps to Reproduce

Code snippet

import { Unkey } from "@unkey/api";

async function createApiKey() {
  const unkey = new Unkey({ rootKey: "<UNKEY_ROOT_KEY>" });

  const response = await unkey.keys.create({
    apiId: "<UNKEY_API_ID>",
    refill: { interval: "daily", amount: 100 },
  });

  console.error("Response object: ", response);
  console.error("Error message: ", response.error?.message); // message is undefined
}

createApiKey();

Actual result:

Response object:  {
  error: {
    error: {
      code: 'BAD_REQUEST',
      docs: 'https://unkey.dev/docs/api-reference/errors/code/BAD_REQUEST',
      message: 'remaining must be set if you are using refill.',
      requestId: 'req_*************'
    }
  }
}
Error message:  undefined

Expected behavior

  1. The response object should contain one error property (no nested error fields)
  2. The provided code snippet should log the actual error message from the response, as per the TypeScript definition and the actual response structure.

Other information

No response

Screenshots

Note that, @unkey/api types work correctly and TS autocomplete expects message property as it has to:

image

Version info

- OS: macOS 13.5.2 (22G91)
- Node: v20.9.0
- npm: 10.1.0
@unrenamed unrenamed added Bug Something isn't working Needs Approval Needs approval from Unkey labels Oct 13, 2024
@unrenamed
Copy link
Contributor Author

@chronark I think this one is critical. It already affected me while working on templates. May I ask you to verify if this is still reproducible?

@unrenamed
Copy link
Contributor Author

cc @perkinsjr

@perkinsjr perkinsjr added Core Team and removed Needs Approval Needs approval from Unkey labels Oct 22, 2024
@unrenamed
Copy link
Contributor Author

@perkinsjr @chronark Question: what determines if a bug qualifies for points? I haven’t found any new info in the guidelines. For example, this one is approved, but no points yet. Just curious about how the system works (yeah, after 3 weeks of participating 😅)

@chronark
Copy link
Collaborator

/award 150

Copy link

oss-gg bot commented Oct 25, 2024

Awarding unrenamed: 150 points 🕹️ Well done! Check out your new contribution on oss.gg/unrenamed

@chronark chronark self-assigned this Oct 25, 2024
@chronark
Copy link
Collaborator

@MichaelUnkey is on this btw, it's indeed a dumb mistake in our sdk

@unrenamed
Copy link
Contributor Author

@chronark thanks for the update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Core Team
Projects
None yet
Development

No branches or pull requests

4 participants