Skip to content

Commit

Permalink
fix app error on bad request
Browse files Browse the repository at this point in the history
  • Loading branch information
auumgn committed Mar 21, 2024
1 parent 96e31cc commit 5b21857
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/affiliation/affiliation-update.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Add or edit affiliation
</h1>
<div>
<jhi-alert-error></jhi-alert-error>
<app-error-alert></app-error-alert>
<div class="form-group">
<label class="form-control-label" i18n="@@gatewayApp.assertionServiceAssertion.email.string" for="field_email"
>Email</label
Expand Down
8 changes: 5 additions & 3 deletions ui/src/app/affiliation/affiliation-update.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core'
import { Component, ErrorHandler, Inject, OnInit } from '@angular/core'
import { AbstractControl, FormBuilder, FormGroup, ValidatorFn, Validators } from '@angular/forms'
import { ActivatedRoute } from '@angular/router'
import * as moment from 'moment'
Expand All @@ -17,6 +17,7 @@ import {
} from '../app.constants'
import { AlertService } from '../shared/service/alert.service'
import { faBan, faSave } from '@fortawesome/free-solid-svg-icons'
import { ErrorService } from '../error/service/error.service'

function dateValidator() {
return (formGroup: FormGroup) => {
Expand Down Expand Up @@ -168,7 +169,8 @@ export class AffiliationUpdateComponent implements OnInit {
protected dateUtilService: DateUtilService,
protected activatedRoute: ActivatedRoute,
private alertService: AlertService,
private fb: FormBuilder
private fb: FormBuilder,
@Inject(ErrorHandler) private errorService: ErrorService
) {}

ngOnInit() {
Expand Down Expand Up @@ -262,7 +264,6 @@ export class AffiliationUpdateComponent implements OnInit {
this.affiliationService.create(assertion).subscribe({
next: () => {
this.onSaveSuccess()
// TODO: add alerttype
this.alertService.broadcast(AlertType.AFFILIATION_CREATED)
},
error: (err) => this.onSaveError(err),
Expand Down Expand Up @@ -318,6 +319,7 @@ export class AffiliationUpdateComponent implements OnInit {
}

protected onSaveError(err: any) {
this.errorService.handleError(err)
console.error(err)
this.isSaving = false
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/error/error-alert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppError, ErrorAlert } from './model/error.model'

@Component({
selector: 'app-error-alert',
templateUrl: './error-alert.component.html'
templateUrl: './error-alert.component.html',
})
export class ErrorAlertComponent implements OnInit {
alerts: any[] = []
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/error/service/error.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ErrorService implements ErrorHandler {

handleError(error: any) {
if (error instanceof HttpErrorResponse) {
this.errors.next(new AppError(error.status, error.message))
this.errors.next(new AppError(error.status, error.error.title))
} else {
console.error('Unknown error occurred', error)
}
Expand Down

0 comments on commit 5b21857

Please sign in to comment.