DELETE request give 204 response code from Insomnia/Postman, but from the frontend it gives error for Delete request.Please find my Service code below :
public bool Dissociate(string envCode, string serialNumber, string gatewayType) { envCode.ThrowIfNull(); serialNumber.ThrowIfNull(); gatewayType.ThrowIfNull(); if (!IsAssociated(envCode, serialNumber, gatewayType)) { _logService.Warn($"DspService - Dissociate - {gatewayType} {serialNumber} not associated to DSP tenant on environment {envCode}"); return false; } EnvironmentSettings dspEnvSettings = GetEnvironmentSettings(envCode); string baseUri = DspHelper.GetBaseUriByAction(dspEnvSettings, DspActionType.Dissociate); string dspDeviceId = DspHelper.BuildDeviceId(serialNumber, gatewayType, true); string uri = $"{baseUri}/registry/devices/{dspDeviceId}/claim"; var body = new { Claimable = true }; try { var authToken = GetAuthorizationHeader(dspEnvSettings, DspActionType.Dissociate); RunDspCommand<bool>(dspEnvSettings, uri, authToken, body, HttpMethod.Put, DspActionType.Dissociate); return true; } catch (Exception e) { _logService.ErrorException(e, $"DspService - Dissociate - Error dissociating {gatewayType} {serialNumber} on environment {envCode}. {uri}"); throw; } }
Please find my insomnia response:
CONTROLLER :
[AcceptVerbs("DELETE")] [Route("dissociate")] public bool Dissociate([FromUri] string gatewayType, [FromUri] string gatewaySerial) { if (string.IsNullOrEmpty(gatewaySerial) || string.IsNullOrEmpty(gatewayType)) { this.BadRequestResponse(); } var connectedUser = this.permissionService.GetConnectedUser(); this.permissionService.CheckRolePermission(connectedUser.Role, PermissionConstant.DissociateComX); bool hasSucceeded = this.dspService.Dissociate(connectedUser.CurrentEnvironment, gatewaySerial, gatewayType); if (hasSucceeded) { this.applicationDataAccess.LogAction(connectedUser.CurrentEnvironment, connectedUser.Email, LogActionConstants.Action.DissociateComX, string.Format(LogActionConstants.Message.DissociateComX, gatewayType, gatewaySerial)); } else { this.BadRequestResponse("cannot deprovioned comx"); } return hasSucceeded; }
It gives the exception in the Service Code:
RunDspCommand<bool>(dspEnvSettings, uri, authToken, body, HttpMethod.Put, DspActionType.Dissociate);
Below is my front end code.
controller.ts
dissociateGateway() { if (!this.isDspGateway || this.isLoadingDspState || this.isDissociating || this.gateway.FirmwareUpgradeWorkflow || this.gateway.DeleteGatewayWorkflow || !this.isAssociated()) { return; } this.modalService.confirm( `The ${this.gateway.Type} ${this.gateway.SerialNumber} will be dissociated from its DSP tenant ${this .dspGatewayState.Tenant}.`,'Are you sure you want to dissociate the gateway from DSP tenant?') .then(() => { this.isDissociating = true; this.dspService.dissociate(this.gateway.Type, this.getDeviceId()) .then(() => this.getDspGatewayState()) .catch((e) => { if (e) { this.modalService.error('Error dissociating the gateway. Please retry later'); } }) .finally(() => this.isDissociating = false); }); }
service.ts
dissociate(gatewayType: string, gatewaySerial: string): ng.IPromise<boolean> { var uri = this.ROUTES.dissociate .replace('{:gatewayType}', gatewayType.toString()) .replace('{:gatewaySerial}', gatewaySerial); return this.restService .delete(uri, null) .then((response: any) => { return response; }) .catch((response: any) => { return this.$q.reject(response); });}
Path :
dissociate: '/dsp/dissociate?gatewaytype={:gatewayType}&gatewaySerial={:gatewaySerial}',
If you need more information please comment below.Please help me.