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

Add api key to error report payload #228

Merged
merged 2 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void beforeNotify(Report report) {
assertNotNull(report);
JSONObject json = getJson(report);

assertEquals(2, json.length());
assertEquals(3, json.length());

JSONObject event = json.getJSONArray("events").getJSONObject(0);
assertNotNull(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private static void checkFileMatchesErrorReport(File file, Error error) throws E
assertFalse(file.length() <= 0);

// ensure the file can be serialised into JSON report
JSONObject memory = getJsonObjectFromReport(new Report(file));
JSONObject disk = getJsonObjectFromReport(new Report(error));
JSONObject memory = getJsonObjectFromReport(new Report("api-key", file));
JSONObject disk = getJsonObjectFromReport(new Report("api-key", error));

// validate info
validateReportPayload(memory);
Expand All @@ -118,7 +118,7 @@ private static void checkFileMatchesErrorReport(File file, Error error) throws E

static void validateReportPayload(JSONObject payload) throws JSONException {
assertNotNull(payload);
assertEquals(2, payload.length());
assertEquals(3, payload.length());

JSONArray events = payload.getJSONArray("events");
assertNotNull(events);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ReportTest {
public void setUp() throws Exception {
config = new Configuration("example-api-key");
Error error = new Error.Builder(config, new RuntimeException("Something broke"), null).build();
report = new Report(error);
report = new Report("api-key", error);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ void notify(@NonNull Error error, @NonNull DeliveryStyle style, @Nullable Callba
}

// Build the report
Report report = new Report(error);
Report report = new Report(config.getApiKey(), error);

if (callback != null) {
callback.beforeNotify(report);
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/bugsnag/android/ErrorStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void run() { // Look up all saved error files

private void flushErrorReport(File errorFile, ErrorReportApiClient errorReportApiClient) {
try {
Report report = new Report(errorFile);
Report report = new Report(config.getApiKey(), errorFile);
errorReportApiClient.postReport(config.getEndpoint(), report, config.getErrorApiHeaders());

Logger.info("Deleting sent error file " + errorFile.getName());
Expand Down
11 changes: 8 additions & 3 deletions sdk/src/main/java/com/bugsnag/android/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,29 @@ public class Report implements JsonStream.Streamable {
@Nullable
private Error error;
private Notifier notifier;
private String apiKey;

Report(@Nullable File errorFile) {
Report(@NonNull String apiKey, @Nullable File errorFile) {
this.error = null;
this.errorFile = errorFile;
this.notifier = Notifier.getInstance();
this.apiKey = apiKey;
}

Report(@Nullable Error error) {
Report(@NonNull String apiKey, @Nullable Error error) {
this.error = error;
this.errorFile = null;
this.notifier = Notifier.getInstance();
this.apiKey = apiKey;
}

@Override
public void toStream(@NonNull JsonStream writer) throws IOException {
// Create a JSON stream and top-level object
writer.beginObject();

writer.name("apiKey").value(apiKey);

// Write the notifier info
writer.name("notifier").value(notifier);

Expand Down Expand Up @@ -64,8 +69,8 @@ public Error getError() {
return error;
}

@Deprecated
public void setApiKey(@NonNull String apiKey) {
this.apiKey = apiKey;
}

public void setNotifierVersion(@NonNull String version) {
Expand Down