Skip to content

retriesCount not defined in interface FastifyReplyFromHooks #296

Description

@MaximeCheramy

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.14.0

Plugin version

8.4.3

Node.js version

18

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Ubuntu 22.04

Description

It seems possible to configure the number of retries according to the documentation and the code (https://github.com/fastify/fastify-reply-from/blob/master/README.md)

However, in the types I don't see anything related to retriesCount. Is it simply missing or did I misunderstood how to configure it?

Steps to Reproduce

Try to configure retriesCount in TypeScript.

Expected Behavior

No response

Activity

  1. Uzlopak commented on Mar 7, 2023

    @Uzlopak
    Contributor

    It should be defined in FastifyReplyFromOptions but is missing there.

    I am also wondering if it is implemented correct. I would expect that if i set options on registering the plugin than that they become the default settings for the actual reply.from call.

    Current codebase is like this

    const disableRequestLogging = opts.disableRequestLogging || false
    
      fastify.decorateReply('from', function (source, opts) {
        opts = opts || {}
        const req = this.request.raw
        const onResponse = opts.onResponse
        const rewriteHeaders = opts.rewriteHeaders || headersNoOp
        const rewriteRequestHeaders = opts.rewriteRequestHeaders || requestHeadersNoOp
        const getUpstream = opts.getUpstream || upstreamNoOp
        const onError = opts.onError || onErrorDefault
        const retriesCount = opts.retriesCount || 0
        const maxRetriesOn503 = opts.maxRetriesOn503 || 10
    
    // And so on

    I would have expected something like this:

    const disableRequestLogging = opts.disableRequestLogging || false
    const defaultOnResponse = opts.onResponse
    const defaultRewriteHeaders = opts.onResonse || headersNoOp
    const defaultGetUpstream = opts.getUpstream || upstreamNoOp
    const defaultOnError = opts.onError || onErrorDefault
    const defaultRetriesCount = opts.retriesCount || 0
    const defaultMaxRetriesOn503 = opts.maxRetriesOn503 ?? 10
    
      fastify.decorateReply('from', function (source, opts) {
        opts || (opts = {})
        const req = this.request.raw
        const onResponse = opts.onResponse || defaultOnResponse
        const rewriteHeaders = opts.rewriteHeaders || defaultRewriteHeaders
        const rewriteRequestHeaders = opts.rewriteRequestHeaders || requestHeadersNoOp
        const getUpstream = opts.getUpstream || defaultGetUpstream
        const onError = opts.onError || defaultOnError
        const retriesCount = opts.retriesCount ?? defaultRetriesCount
        const maxRetriesOn503 = opts.maxRetriesOn503 ?? defaultMaxRetriesOn503
    
    // And so on

    In the current code you can not even set maxRetriesOn503 to 0 because of using || and not ??

    I typed this comment with my phone so there can be typos in the code.

    @mcollina
    @climba03003

  2. mcollina commented on Mar 7, 2023

    @mcollina
    Member

    if the implementation is not correct, I would love to see a test/repro to verify the problem.


    @MaximeCheramy would you like to send a PR to add retriesCount to the types? I think it should go to the @fastify/reply-from module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions