-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also allow to clear all the game data when cache panic
- Loading branch information
1 parent
a64b352
commit 139f77b
Showing
18 changed files
with
179 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
business/src/main/java/com/kevinguanchedarias/owgejava/entity/TrackBrowser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.kevinguanchedarias.owgejava.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.Instant; | ||
|
||
@Data | ||
@Entity | ||
@Table | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true) | ||
public class TrackBrowser { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@EqualsAndHashCode.Include | ||
private Long id; | ||
|
||
String method; | ||
String jsonContent; | ||
|
||
Instant createdAt; | ||
} |
7 changes: 7 additions & 0 deletions
7
...ness/src/main/java/com/kevinguanchedarias/owgejava/repository/TrackBrowserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kevinguanchedarias.owgejava.repository; | ||
|
||
import com.kevinguanchedarias.owgejava.entity.TrackBrowser; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TrackBrowserRepository extends JpaRepository<TrackBrowser, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
game-frontend/modules/owge-universe/src/lib/services/error-logging.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {UniverseGameService} from './universe-game.service'; | ||
import {stringify} from 'flatted'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ErrorLoggingService { | ||
private readonly originalWarn = console.warn.bind(console); | ||
|
||
constructor(private universeGameService: UniverseGameService) { | ||
window.onerror = (msg, url, lineNo, columnNo, error) => { | ||
console.log('ups',msg,lineNo, error); | ||
}; | ||
['warn','error'].forEach(level => this.intercept(level)); | ||
} | ||
|
||
private intercept(method: string): void { | ||
// eslint-disable-next-line no-console | ||
const original = console[method].bind(console); | ||
// eslint-disable-next-line no-console | ||
console[method] = (...args) => { | ||
// eslint-disable-next-line no-console | ||
this.doReport(method, args).then(() => console.debug('Logged data ',method, args)); | ||
original(...args); | ||
}; | ||
} | ||
|
||
private async doReport(method: string, args: unknown[]): Promise<void> { | ||
try { | ||
const content = stringify(args); | ||
if(content.length > 100) { | ||
await this.universeGameService.requestWithAutorizationToContext( | ||
'game', 'post', `track-browser/${method}`, content | ||
).toPromise(); | ||
} else { | ||
this.originalWarn('Not logging due to insufficient information',content); | ||
} | ||
}catch (e) { | ||
this.originalWarn('unable to track browser',e ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...rest/src/main/java/com/kevinguanchedarias/owgejava/rest/game/TrackBrowserRestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.kevinguanchedarias.owgejava.rest.game; | ||
|
||
import com.kevinguanchedarias.owgejava.entity.TrackBrowser; | ||
import com.kevinguanchedarias.owgejava.repository.TrackBrowserRepository; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.context.annotation.ApplicationScope; | ||
|
||
import java.time.Instant; | ||
|
||
@RestController | ||
@RequestMapping("game/track-browser") | ||
@ApplicationScope | ||
@AllArgsConstructor | ||
public class TrackBrowserRestService { | ||
private final TrackBrowserRepository trackBrowserRepository; | ||
|
||
@PostMapping("warn") | ||
public void warn(@RequestBody String body) { | ||
doTrack("warn", body); | ||
} | ||
|
||
@PostMapping("error") | ||
public void error(@RequestBody String body) { | ||
doTrack("error", body); | ||
} | ||
|
||
private void doTrack(String method, String content) { | ||
trackBrowserRepository.save( | ||
TrackBrowser.builder() | ||
.method(method) | ||
.jsonContent(content) | ||
.createdAt(Instant.now()) | ||
.build() | ||
); | ||
} | ||
} |