Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/user.ts (TypeScript)

Code before:
        const { username, reportDescription: report } = req.body;

        if (!username || !report || report === '') {
          // NOTE: Do we want to log these instances?
          void reply.code(400);
          return {
            type: 'danger',
            message: 'flash.provide-username'
          } as const;
        }

        await fastify.sendEmail({
          from: 'team@freecodecamp.org',
          to: 'support@freecodecamp.org',
          cc: user.email,
          subject: `Abuse Report: Reporting ${username}'s profile`,
          text: generateReportEmail(user, username, report)
        });

        return {
          type: 'info',
          message: 'flash.report-sent',
          variables: { email: user.email }
        } as const;
      } catch (err) {
        fastify.log.error(err);
        void reply.code(500);
        return {
          type: 'danger',
          message:
            'Oops! Something went wrong. Please try again in a moment or contact support@freecodecamp.org if the error persists.'
        } as const;
      }
    }
  );

  done();
};

/**
 * Plugin containing GET routes for user account management. They are kept
 * separate because they do not require CSRF protection.
 *
 * @param fastify The Fastify instance.
 * @param _options Options passed to the plugin via `fastify.register(plugin, options)`.
 * @param done Callback to signal that the logic has completed.
 */
export const userGetRoutes: FastifyPluginCallbackTypebox = (
  fastify,
  _options,
  done

Review comment (suggestion):
One issue is that that api-server redirects the user back to `<origin>/<username>` if there's an error. There's a fair bit of work (and it's not the highest priority), but could you add a todo?
```suggestion
        fastify.log.error(err);
        // TODO: redirect to the reported user's profile if there's an error
```

Code after:
        const { username, reportDescription: report } = req.body;

        if (!username || !report || report === '') {
          // NOTE: Do we want to log these instances?
          void reply.code(400);
          return {
            type: 'danger',
            message: 'flash.provide-username'
          } as const;
        }

        await fastify.sendEmail({
          from: 'team@freecodecamp.org',
          to: 'support@freecodecamp.org',
          cc: user.email,
          subject: `Abuse Report: Reporting ${username}'s profile`,
          text: generateReportEmail(user, username, report)
        });

        return {
          type: 'info',
          message: 'flash.report-sent',
          variables: { email: user.email }
        } as const;
      } catch (err) {
        fastify.log.error(err);
        // TODO: redirect to the reported user's profile if there's an error
        void reply.code(500);
        return {
          type: 'danger',
          message:
            'Oops! Something went wrong. Please try again in a moment or contact support@freecodecamp.org if the error persists.'
        } as const;
      }
    }
  );

  done();
};

/**
 * Plugin containing GET routes for user account management. They are kept
 * separate because they do not require CSRF protection.
 *
 * @param fastify The Fastify instance.
 * @param _options Options passed to the plugin via `fastify.register(plugin, options)`.
 * @param done Callback to signal that the logic has completed.
 */
export const userGetRoutes: FastifyPluginCallbackTypebox = (
  fastify,
  _options,