makenotion / notion-sdk-js

Official Notion JavaScript Client
https://developers.notion.com/docs
MIT License
4.82k stars 566 forks source link

UnknownHTTPResponseError: Request to Notion API failed with status: 502 #457

Open britonmarketing opened 11 months ago

britonmarketing commented 11 months ago

This one is a duplicate of https://github.com/makenotion/notion-sdk-js/issues/172, it occurs for many users and needs to be re-open

Server Error UnknownHTTPResponseError: Request to Notion API failed with status: 502

This error happened while generating the page. Any console logs will be displayed in the terminal window.

I have about 30 pages, it occurs randomly on a few of them during the build

Console:

Uncaught UnknownHTTPResponseError: Request to Notion API failed with status: 502 at buildRequestError at Client.request at process.processTicksAndRejections at async getProps at async Object.renderToHTML at async doRender at async cacheEntry1.responseCache.get.incrementalCache.incrementalCache at async

interpolack commented 11 months ago

thanks for opening. adding my name to the list of people it's happening to

lailo commented 11 months ago

I've been experiencing this issue for a few days while collecting page data in my Next.js app. It used to occur randomly and only occasionally, but now it happens every time.

@notionhq/client warn: request fail {
   code: 'notionhq_client_response_error',
   message: 'Request to Notion API failed with status: 502'
}
michalpuchmertl commented 11 months ago

Same for me.

Badestrand commented 11 months ago

same and from #172 it seems to be a really prevalent issue.

DZGoldman commented 11 months ago

same - hadn't seen this error before but now hitting it consistently

AlAgilly commented 11 months ago

Same. It even occurs for just reading small databases (~15 pages). It's reoccurring at an increasing amount the past week.. Error:

@notionhq/client warn: request fail {
  code: 'notionhq_client_response_error',
  message: 'Request to Notion API failed with status: 502'
}

My code can be found here: https://github.com/AlAgilly/yues_website/blob/main/server/index.js

Willing to give access to my databases if needed

stensrud commented 11 months ago

I'm getting the same problem

lakeesiv commented 11 months ago

Im also getting this aswell

accounts01 commented 11 months ago

+1. I'm experiencing this as well.

BenMt commented 11 months ago

+1

juanicortesl commented 11 months ago

+1

ziegfried commented 11 months ago

The main problem here is that the notion client holds on to the connection and once it hits a 502 error, every subsequent request also results in such an error. Even creating a new notion client instance doesn't solve the issue (it uses the same http agent instance).

Our current workaround:

Something along the lines:

import { Agent } from "https";
import { Client } from "@notionhq/client";

let agent, notion;

function reset() {
    if (agent) agent.destroy();
    agent = new Agent();
    notion = new Client({ auth: process.env.NOTION_TOKEN, agent });
}

reset();

// Using the notion client:
try {
    // do something with notion client
} catch(e) {
    const errorText = e.toString();
    if (
      errorText.includes("PgPoolWaitConnectionTimeout") ||
      errorText.includes("Request timed out") ||
      errorText.includes("Request to Notion API has timed out") ||
      errorText.includes("Request to Notion API failed with status: 502")
    ) {
      reset();
    }
}
Badestrand commented 11 months ago

I now also get the error

@notionhq/client warn: request fail {
  code: 'service_unavailable',
  message: 'Request timed out waiting to connect to a database. Please try again later.'
}

sometimes.

TopherTimeMachine commented 11 months ago

I just starting getting this message while trying to create a page. It was working a few days ago.

@notionhq/client warn: request fail {
  code: 'notionhq_client_request_timeout',
  message: 'Request to Notion API has timed out'
}

I tried the reset() solution above and didn't seem to work. What other options are there? Notion support or dev team listening in?

pulbyte commented 11 months ago

I am getting both these errors, almost 50% of time while GET:/ notion page, While updating a notion page, While querying a Notion database.

@notionhq/client warn: request fail {
 code: 'notionhq_client_request_timeout',
 message: 'Request to Notion API has timed out'
}

@notionhq/client warn: request fail {
 code: 'notionhq_client_response_error',
 message: 'Request to Notion API failed with status: 502'
}

Although retrying works, But It's still not viable solution and Notion API has almost become unreliable recently.

NodeJs version : 20 @notionhq/client": "^2.2.7"

remihuigen commented 11 months ago

Same here! Just contacted support, since i don't think they are gonna respond to this github issue. Will post update if I get a response

Smidgens commented 11 months ago

I'm still getting this occasionally on reads, with no discernible pattern (reads of any size, random hours...). My workaround is to simply catch the error and retry. So far I think it's always succeeded on the second try but...

It would be great if Notion either added a mention of 502s to the API docs, or silently handled the error in the SDK (make it an opt-in flag even).

remihuigen commented 11 months ago

Same here! Just contacted support, since i don't think they are gonna respond to this github issue. Will post update if I get a response

Just got a reply from support:

I can understand how important this is for you and the inconvenience this created to your workflow.   In the last couple of days, Notion and API experienced incidents with degraded performance. I'm happy to inform you that this has now been resolved!   You should be good to go! :)

In the last 24 hours I've only occasionally encountered 502s, but they are still popping up now and then. I also don't buy Notion supports claim that it has been 'an issue in the last couple of days' and that it should be resolved now. Since as far as I can tell the 502s have been happening for over two weeks.

Anyway, I believe they are still not willing to acknowledge the shabby state of their public API, and we should not except any improvements soon. My conclusion is that their API is fun for internal projects, but not production ready anytime soon.

I've implemented a workaround where the app retries fetching the API if the response is a 502, with a max of 5 retries. So far I haven't needed the fifth retry.

linkyndy commented 11 months ago

Same issue here, only that every requests times out or takes >20s to respond. Basically, we cannot use the API. And we haven't heard back on any of our tickets on any of the support channels about this.

DerickIT commented 4 months ago

I still have this problem. Can I solve it in other ways?