rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar

Home Page:https://docs.rollbar.com/docs/javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing 'environment' key. Missing 'revision' or 'head_long' key. 'environment' key must be a string

davidutramn opened this issue · comments

I am using angular 12, and rollbar with Jira integration, so I am receiving the error details, and I keep getting this error with the status 422 even though I am sending the environment field (it is correct in the error details).
The rollbar itself is working fine, Am I doing something wrong?

My angular code:

rollbar.ts

import * as Rollbar from 'rollbar';
import { Injectable, Inject, InjectionToken, ErrorHandler } from '@angular/core';
import { environment } from './environments/environment';

const rollbarConfig: Rollbar.Configuration = {
  accessToken: environment.ROLLBAR.KEY,
  captureUncaught: true,
  captureUnhandledRejections: true,
  endpoint: environment.ROLLBAR.ENDPOINT,
  environment: environment.ROLLBAR.ENV,
  payload: {
    environment: environment.ROLLBAR.ENV,
    context: 'home#index'
  }
};

export const RollbarService = new InjectionToken<Rollbar>('rollbar');
@Injectable()
export class RollbarErrorHandler implements ErrorHandler {
  constructor(@Inject(RollbarService) private rollbar: Rollbar) { }

  handleError(err: { originalError: any }): void {
    if (environment?.ROLLBAR?.ENV) {
      this.rollbar.error(err.originalError || err);
    }
  }
}

export function rollbarFactory(): Rollbar {
  if (environment?.ROLLBAR?.ENV) {
    return new Rollbar(rollbarConfig);
  }
}

app.module

import { RollbarService, rollbarFactory, RollbarErrorHandler } from '../rollbar';
...
providers: [
    { provide: ErrorHandler,   useClass: RollbarErrorHandler },
    { provide: RollbarService, useFactory: rollbarFactory },  ],
...

The error message indicates that you are posting to the endpoint for deploy events. (api.rollbar.com/api/1/deploy/) Rollbar.js sends a payload that isn't compatible with that endpoint. The correct endpoint is api.rollbar.com/api/1/item/.

The example code shows you are setting a custom endpoint (endpoint: environment.ROLLBAR.ENDPOINT). That shouldn't be necessary except when setting up a proxy or otherwise diverting payloads to some custom receiver.